From 69886df6dd9a3eeee5ea208ba06936b29d431437 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Mon, 11 Jan 2016 21:15:38 -0500 Subject: [PATCH] Add keyboard shortcut for / Change-Id: If9a068eb199b5a16df8e5b4f80c7efe92353c088 --- polygerrit-ui/app/elements/gr-search-bar.html | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/polygerrit-ui/app/elements/gr-search-bar.html b/polygerrit-ui/app/elements/gr-search-bar.html index d9ad1a3772..7a38c6f8d4 100644 --- a/polygerrit-ui/app/elements/gr-search-bar.html +++ b/polygerrit-ui/app/elements/gr-search-bar.html @@ -67,7 +67,20 @@ limitations under the License. notify: true, observer: '_valueChanged', }, + _inputVal: String, + _boundKeyHandler: { + type: Function, + value: function() { return this._handleKey.bind(this); }, + } + }, + + attached: function() { + document.body.addEventListener('keydown', this._boundKeyHandler); + }, + + detached: function() { + document.body.removeEventListener('keydown', this._boundKeyHandler); }, _valueChanged: function(value) { @@ -86,6 +99,17 @@ limitations under the License. page.show('/q/' + this._inputVal); }, + _handleKey: function(e) { + if (util.shouldSupressKeyboardShortcut(e)) { return; } + e.preventDefault(); + switch(e.keyCode) { + case 191: // '/' + var s = this.$.searchInput; + s.focus(); + s.setSelectionRange(0, s.value.length); + break; + } + }, }); })();