Fix ctrl+enter shortcut in reply dialog When a gr-account-list is focused (e.g. when adding reviewers), the autocomplete element prevents default for a few specific keypresses. This was causing the ctrl+enter (and meta+enter) shortcut to fail to fire in the reply dialog. With this change, a check for modifiers is performed before acting on an enter keypress in the autocomplete. Modifier checking for the other keys in the function was not added to avoid unintended side effects (including alternative keyboard layouts). Bug: Issue 8971 Change-Id: I9cb25fa061051b12fd3bda111fa24bc42fbc303c
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.html b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.html index c289aa3..ef058a5 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.html +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.html
@@ -15,8 +15,8 @@ limitations under the License. --> <link rel="import" href="../../../bower_components/polymer/polymer.html"> -<link rel="import" href="../../../bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html"> <link rel="import" href="../../../bower_components/paper-input/paper-input.html"> +<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html"> <link rel="import" href="../../shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.html"> <link rel="import" href="../../shared/gr-cursor-manager/gr-cursor-manager.html"> <link rel="import" href="../../shared/gr-icons/gr-icons.html">
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js index f39398f..634bc00 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js
@@ -165,6 +165,10 @@ _selected: Object, }, + behaviors: [ + Gerrit.KeyboardShortcutBehavior, + ], + observers: [ '_maybeOpenDropdown(_suggestions, _focused)', '_updateSuggestions(text, threshold, noDebounce)', @@ -305,6 +309,7 @@ } break; case 13: // Enter + if (this.modifierPressed(e)) { break; } e.preventDefault(); this._handleInputCommit(); break;
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html index d257cdd..a72511e 100644 --- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html +++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html
@@ -496,6 +496,18 @@ assert.isTrue(listener.called); }); + test('enter with modifier does not complete', () => { + const handleSpy = sandbox.spy(element, '_handleKeydown'); + const commitStub = sandbox.stub(element, '_handleInputCommit'); + MockInteractions.pressAndReleaseKeyOn( + element.$.input, 13, 'ctrl', 'enter'); + assert.isTrue(handleSpy.called); + assert.isFalse(commitStub.called); + MockInteractions.pressAndReleaseKeyOn( + element.$.input, 13, null, 'enter'); + assert.isTrue(commitStub.called); + }); + suite('warnUncommitted', () => { let inputClassList; setup(() => {