diff --git a/app/assets/javascripts/discourse/lib/autocomplete.js.es6 b/app/assets/javascripts/discourse/lib/autocomplete.js.es6 index c30a1071039..bfaa65d49af 100644 --- a/app/assets/javascripts/discourse/lib/autocomplete.js.es6 +++ b/app/assets/javascripts/discourse/lib/autocomplete.js.es6 @@ -240,6 +240,7 @@ export default function(options) { var pos = null; var vOffset = 0; var hOffset = 0; + if (isInput) { pos = { left: 0, @@ -247,19 +248,14 @@ export default function(options) { }; vOffset = -32; hOffset = 0; - } if (options.treatAsTextarea) { - pos = me.caretPosition({ - pos: completeStart, - key: options.key - }); - hOffset = 27; - vOffset = -32; } else { pos = me.caretPosition({ pos: completeStart, key: options.key }); + hOffset = 27; + if (options.treatAsTextarea) vOffset = -32; } div.css({ left: "-1000px" diff --git a/app/assets/javascripts/discourse/lib/search.js.es6 b/app/assets/javascripts/discourse/lib/search.js.es6 index fea2dd7f136..78318682302 100644 --- a/app/assets/javascripts/discourse/lib/search.js.es6 +++ b/app/assets/javascripts/discourse/lib/search.js.es6 @@ -130,7 +130,13 @@ export function isValidSearchTerm(searchTerm) { } }; -export function applySearchAutocomplete($input, siteSettings) { +export function applySearchAutocomplete($input, siteSettings, appEvents) { + const afterComplete = function() { + if (appEvents) { + appEvents.trigger("search-autocomplete:after-complete"); + } + }; + $input.autocomplete({ template: findRawTemplate('category-tag-autocomplete'), key: '#', @@ -145,15 +151,17 @@ export function applySearchAutocomplete($input, siteSettings) { }, dataSource(term) { return searchCategoryTag(term, siteSettings); - } + }, + afterComplete }); $input.autocomplete({ template: findRawTemplate('user-selector-autocomplete'), - dataSource: term => userSearch({ term, undefined, includeGroups: true }), key: "@", width: '100%', treatAsTextarea: true, - transformComplete: v => v.username || v.name + transformComplete: v => v.username || v.name, + dataSource: term => userSearch({ term, includeGroups: true }), + afterComplete }); }; diff --git a/app/assets/javascripts/discourse/widgets/header.js.es6 b/app/assets/javascripts/discourse/widgets/header.js.es6 index 24c59fe7ae1..c74dac720ff 100644 --- a/app/assets/javascripts/discourse/widgets/header.js.es6 +++ b/app/assets/javascripts/discourse/widgets/header.js.es6 @@ -262,7 +262,7 @@ export default createWidget('header', { Ember.run.schedule('afterRender', () => { const $searchInput = $('#search-term'); $searchInput.focus().select(); - applySearchAutocomplete($searchInput, this.siteSettings); + applySearchAutocomplete($searchInput, this.siteSettings, this.appEvents); }); } }, 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 eae413b877e..689e749ee8e 100644 --- a/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 +++ b/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 @@ -6,11 +6,13 @@ 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, shiftKeyEntry: false }; + this.appEvents.on("search-autocomplete:after-complete", () => { + this.state.afterAutocomplete = true; + }); + + return { afterAutocomplete: false }; }, buildAttributes(attrs) { @@ -19,22 +21,13 @@ createWidget('search-term', { placeholder: attrs.contextEnabled ? "" : I18n.t('search.title') }; }, - 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 { - state.autocompleteIsOpen = false; - } - }, - keyUp(e) { - const state = this.state; - if (e.which === 13 && !state.shiftKeyEntry && !state.autocompleteIsOpen) { - return this.sendWidgetAction('fullSearch'); + if (e.which === 13) { + if (this.state.afterAutocomplete) { + this.state.afterAutocomplete = false; + } else { + return this.sendWidgetAction('fullSearch'); + } } const val = this.attrs.value;