FIX: Do not trigger fullpage search when selecting autocomplete term with enter.

This commit is contained in:
Guo Xiang Tan 2017-03-07 11:54:15 +08:00
parent f3a7e398ca
commit 60b7453f3f
4 changed files with 27 additions and 30 deletions

View File

@ -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"

View File

@ -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
});
};

View File

@ -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);
});
}
},

View File

@ -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,23 +21,14 @@ 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) {
if (e.which === 13) {
if (this.state.afterAutocomplete) {
this.state.afterAutocomplete = false;
} else {
return this.sendWidgetAction('fullSearch');
}
}
const val = this.attrs.value;
const newVal = $(`#${this.buildId()}`).val();