From 3eb51f0d77111e92876235ce2222bbe1b5039bb0 Mon Sep 17 00:00:00 2001 From: cpradio Date: Fri, 3 Mar 2017 22:48:28 -0500 Subject: [PATCH] FIX: Make it a tad bit harder to accidentally redirect to full page search while autocomplete is open --- .../discourse/widgets/search-menu-controls.js.es6 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 b/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 index 0fe748669ef..eae413b877e 100644 --- a/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 +++ b/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 @@ -6,9 +6,11 @@ createWidget('search-term', { tagName: 'input', buildId: () => 'search-term', buildKey: (attrs) => `search-term-${attrs.id}`, + KEYCODE_AT_SIGN: 50, + KEYCODE_POUND_SIGN: 51, defaultState() { - return { autocompleteIsOpen: false }; + return { autocompleteIsOpen: false, shiftKeyEntry: false }; }, buildAttributes(attrs) { @@ -19,6 +21,9 @@ createWidget('search-term', { keyDown(e) { const state = this.state; + state.shiftKeyEntry = e.shiftKey && + (e.keyCode === this.KEYCODE_AT_SIGN || e.keyCode === this.KEYCODE_POUND_SIGN); + if ($(`#${this.buildId()}`).parent().find('.autocomplete').length !== 0) { state.autocompleteIsOpen = true; } else { @@ -27,7 +32,8 @@ createWidget('search-term', { }, keyUp(e) { - if (e.which === 13 && !this.state.autocompleteIsOpen) { + const state = this.state; + if (e.which === 13 && !state.shiftKeyEntry && !state.autocompleteIsOpen) { return this.sendWidgetAction('fullSearch'); }