Merge pull request #7052 from overleaf/td-suppress-comment-page-up-down

Suppress Page Up/Down keypresses in comment textarea

GitOrigin-RevId: 244bfdc4f1a1470870180a166ba7d2b2792fe614
This commit is contained in:
Tim Down 2022-03-11 15:10:50 +00:00 committed by Copybot
parent 7560404d93
commit 64dd07a50f
2 changed files with 11 additions and 0 deletions

View file

@ -480,6 +480,7 @@ script(type='text/ng-template', id='addCommentEntryTemplate')
expandable-text-area expandable-text-area
ng-model="state.content" ng-model="state.content"
ng-keypress="handleCommentKeyPress($event);" ng-keypress="handleCommentKeyPress($event);"
ng-keydown="handleCommentKeyDown($event);"
placeholder=translate("add_your_comment_here") placeholder=translate("add_your_comment_here")
focus-on="comment:new:open" focus-on="comment:new:open"
) )

View file

@ -31,6 +31,16 @@ App.directive('addCommentEntry', () => ({
scope.onCancel() scope.onCancel()
} }
const ignoreKeysInTextAreas = ['PageDown', 'PageUp']
scope.handleCommentKeyDown = function (ev) {
if (ignoreKeysInTextAreas.includes(ev.key)) {
if (ev.target.closest('textarea')) {
ev.preventDefault()
}
}
}
scope.handleCommentKeyPress = function (ev) { scope.handleCommentKeyPress = function (ev) {
if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) { if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
ev.preventDefault() ev.preventDefault()