mirror of
https://github.com/discourse/discourse.git
synced 2025-02-17 00:35:50 +00:00
FIX: Do not trigger fullpage search when selecting autocomplete term with enter.
This commit is contained in:
parent
f3a7e398ca
commit
60b7453f3f
@ -240,6 +240,7 @@ export default function(options) {
|
|||||||
var pos = null;
|
var pos = null;
|
||||||
var vOffset = 0;
|
var vOffset = 0;
|
||||||
var hOffset = 0;
|
var hOffset = 0;
|
||||||
|
|
||||||
if (isInput) {
|
if (isInput) {
|
||||||
pos = {
|
pos = {
|
||||||
left: 0,
|
left: 0,
|
||||||
@ -247,19 +248,14 @@ export default function(options) {
|
|||||||
};
|
};
|
||||||
vOffset = -32;
|
vOffset = -32;
|
||||||
hOffset = 0;
|
hOffset = 0;
|
||||||
} if (options.treatAsTextarea) {
|
|
||||||
pos = me.caretPosition({
|
|
||||||
pos: completeStart,
|
|
||||||
key: options.key
|
|
||||||
});
|
|
||||||
hOffset = 27;
|
|
||||||
vOffset = -32;
|
|
||||||
} else {
|
} else {
|
||||||
pos = me.caretPosition({
|
pos = me.caretPosition({
|
||||||
pos: completeStart,
|
pos: completeStart,
|
||||||
key: options.key
|
key: options.key
|
||||||
});
|
});
|
||||||
|
|
||||||
hOffset = 27;
|
hOffset = 27;
|
||||||
|
if (options.treatAsTextarea) vOffset = -32;
|
||||||
}
|
}
|
||||||
div.css({
|
div.css({
|
||||||
left: "-1000px"
|
left: "-1000px"
|
||||||
|
@ -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({
|
$input.autocomplete({
|
||||||
template: findRawTemplate('category-tag-autocomplete'),
|
template: findRawTemplate('category-tag-autocomplete'),
|
||||||
key: '#',
|
key: '#',
|
||||||
@ -145,15 +151,17 @@ export function applySearchAutocomplete($input, siteSettings) {
|
|||||||
},
|
},
|
||||||
dataSource(term) {
|
dataSource(term) {
|
||||||
return searchCategoryTag(term, siteSettings);
|
return searchCategoryTag(term, siteSettings);
|
||||||
}
|
},
|
||||||
|
afterComplete
|
||||||
});
|
});
|
||||||
|
|
||||||
$input.autocomplete({
|
$input.autocomplete({
|
||||||
template: findRawTemplate('user-selector-autocomplete'),
|
template: findRawTemplate('user-selector-autocomplete'),
|
||||||
dataSource: term => userSearch({ term, undefined, includeGroups: true }),
|
|
||||||
key: "@",
|
key: "@",
|
||||||
width: '100%',
|
width: '100%',
|
||||||
treatAsTextarea: true,
|
treatAsTextarea: true,
|
||||||
transformComplete: v => v.username || v.name
|
transformComplete: v => v.username || v.name,
|
||||||
|
dataSource: term => userSearch({ term, includeGroups: true }),
|
||||||
|
afterComplete
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -262,7 +262,7 @@ export default createWidget('header', {
|
|||||||
Ember.run.schedule('afterRender', () => {
|
Ember.run.schedule('afterRender', () => {
|
||||||
const $searchInput = $('#search-term');
|
const $searchInput = $('#search-term');
|
||||||
$searchInput.focus().select();
|
$searchInput.focus().select();
|
||||||
applySearchAutocomplete($searchInput, this.siteSettings);
|
applySearchAutocomplete($searchInput, this.siteSettings, this.appEvents);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -6,11 +6,13 @@ createWidget('search-term', {
|
|||||||
tagName: 'input',
|
tagName: 'input',
|
||||||
buildId: () => 'search-term',
|
buildId: () => 'search-term',
|
||||||
buildKey: (attrs) => `search-term-${attrs.id}`,
|
buildKey: (attrs) => `search-term-${attrs.id}`,
|
||||||
KEYCODE_AT_SIGN: 50,
|
|
||||||
KEYCODE_POUND_SIGN: 51,
|
|
||||||
|
|
||||||
defaultState() {
|
defaultState() {
|
||||||
return { autocompleteIsOpen: false, shiftKeyEntry: false };
|
this.appEvents.on("search-autocomplete:after-complete", () => {
|
||||||
|
this.state.afterAutocomplete = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return { afterAutocomplete: false };
|
||||||
},
|
},
|
||||||
|
|
||||||
buildAttributes(attrs) {
|
buildAttributes(attrs) {
|
||||||
@ -19,22 +21,13 @@ createWidget('search-term', {
|
|||||||
placeholder: attrs.contextEnabled ? "" : I18n.t('search.title') };
|
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) {
|
keyUp(e) {
|
||||||
const state = this.state;
|
if (e.which === 13) {
|
||||||
if (e.which === 13 && !state.shiftKeyEntry && !state.autocompleteIsOpen) {
|
if (this.state.afterAutocomplete) {
|
||||||
return this.sendWidgetAction('fullSearch');
|
this.state.afterAutocomplete = false;
|
||||||
|
} else {
|
||||||
|
return this.sendWidgetAction('fullSearch');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const val = this.attrs.value;
|
const val = this.attrs.value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user