From 64dd07a50f9fa9b2fd3ab9a84d5d32494f10fb01 Mon Sep 17 00:00:00 2001 From: Tim Down Date: Fri, 11 Mar 2022 15:10:50 +0000 Subject: [PATCH] Merge pull request #7052 from overleaf/td-suppress-comment-page-up-down Suppress Page Up/Down keypresses in comment textarea GitOrigin-RevId: 244bfdc4f1a1470870180a166ba7d2b2792fe614 --- services/web/app/views/project/editor/review-panel.pug | 1 + .../js/ide/review-panel/directives/addCommentEntry.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/services/web/app/views/project/editor/review-panel.pug b/services/web/app/views/project/editor/review-panel.pug index aa9cff0228..93f9cc9cd6 100644 --- a/services/web/app/views/project/editor/review-panel.pug +++ b/services/web/app/views/project/editor/review-panel.pug @@ -480,6 +480,7 @@ script(type='text/ng-template', id='addCommentEntryTemplate') expandable-text-area ng-model="state.content" ng-keypress="handleCommentKeyPress($event);" + ng-keydown="handleCommentKeyDown($event);" placeholder=translate("add_your_comment_here") focus-on="comment:new:open" ) diff --git a/services/web/frontend/js/ide/review-panel/directives/addCommentEntry.js b/services/web/frontend/js/ide/review-panel/directives/addCommentEntry.js index e844629bfe..efae4696df 100644 --- a/services/web/frontend/js/ide/review-panel/directives/addCommentEntry.js +++ b/services/web/frontend/js/ide/review-panel/directives/addCommentEntry.js @@ -31,6 +31,16 @@ App.directive('addCommentEntry', () => ({ 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) { if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) { ev.preventDefault()