From 64c2ff6f2c53c5844b9536a2124c08724a8fea67 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Wed, 2 Dec 2015 18:02:04 -0500 Subject: [PATCH] Suppress keyboard shortcuts while some elements are in focus Otherwise you could trigger them by typing the appropriate shortcut while inside the search bar, for example. Change-Id: I0ebc3f9235814faac19ec364f185386d8e496f04 --- polygerrit-ui/app/elements/gr-change-list.html | 2 ++ polygerrit-ui/app/elements/gr-change-view.html | 2 ++ polygerrit-ui/app/elements/gr-diff-view.html | 2 ++ polygerrit-ui/app/scripts/util.js | 9 +++++++++ polygerrit-ui/app/test/gr-change-list-test.html | 1 + polygerrit-ui/app/test/gr-change-view-test.html | 1 + 6 files changed, 17 insertions(+) diff --git a/polygerrit-ui/app/elements/gr-change-list.html b/polygerrit-ui/app/elements/gr-change-list.html index a1fd952482..241e8b0407 100644 --- a/polygerrit-ui/app/elements/gr-change-list.html +++ b/polygerrit-ui/app/elements/gr-change-list.html @@ -84,6 +84,8 @@ limitations under the License. }, _handleKey: function(e) { + if (util.shouldSupressKeyboardShortcut(e)) { return; } + var len = (this.changes && this.changes.length) || 0; switch(e.detail.combo) { case 'j': diff --git a/polygerrit-ui/app/elements/gr-change-view.html b/polygerrit-ui/app/elements/gr-change-view.html index da6967dd15..9a008d2122 100644 --- a/polygerrit-ui/app/elements/gr-change-view.html +++ b/polygerrit-ui/app/elements/gr-change-view.html @@ -213,6 +213,8 @@ limitations under the License. }, _handleKey: function(e) { + if (util.shouldSupressKeyboardShortcut(e)) { return; } + switch(e.detail.combo) { case 'a': this._showReplyField(); diff --git a/polygerrit-ui/app/elements/gr-diff-view.html b/polygerrit-ui/app/elements/gr-diff-view.html index 87d4a9942d..c3654d199d 100644 --- a/polygerrit-ui/app/elements/gr-diff-view.html +++ b/polygerrit-ui/app/elements/gr-diff-view.html @@ -314,6 +314,8 @@ limitations under the License. }, _handleKey: function(e) { + if (util.shouldSupressKeyboardShortcut(e)) { return; } + switch(e.detail.combo) { case '[': this._navToFile(this._fileList, -1); diff --git a/polygerrit-ui/app/scripts/util.js b/polygerrit-ui/app/scripts/util.js index 400ed8667f..2f5ecafd05 100644 --- a/polygerrit-ui/app/scripts/util.js +++ b/polygerrit-ui/app/scripts/util.js @@ -38,3 +38,12 @@ util.escapeHTML = function(str) { return util.htmlEntityMap[s]; }); }; + +util.shouldSupressKeyboardShortcut = function(e) { + var target = e.detail.keyboardEvent.target; + return target.tagName == 'INPUT' || + target.tagName == 'TEXTAREA' || + target.tagName == 'SELECT' || + target.tagName == 'BUTTON' || + target.tagName == 'A'; +}; diff --git a/polygerrit-ui/app/test/gr-change-list-test.html b/polygerrit-ui/app/test/gr-change-list-test.html index 01b297cb86..afbd32ac87 100644 --- a/polygerrit-ui/app/test/gr-change-list-test.html +++ b/polygerrit-ui/app/test/gr-change-list-test.html @@ -22,6 +22,7 @@ limitations under the License. + diff --git a/polygerrit-ui/app/test/gr-change-view-test.html b/polygerrit-ui/app/test/gr-change-view-test.html index c016c6a551..3e332bf74c 100644 --- a/polygerrit-ui/app/test/gr-change-view-test.html +++ b/polygerrit-ui/app/test/gr-change-view-test.html @@ -22,6 +22,7 @@ limitations under the License. +