mirror of
https://github.com/discourse/discourse.git
synced 2025-02-18 01:05:00 +00:00
Merge branch 'master' into vdom
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
This commit is contained in:
commit
10aa1923a4
@ -44,7 +44,7 @@ export default function(options) {
|
|||||||
if (options === 'destroy') {
|
if (options === 'destroy') {
|
||||||
Ember.run.cancel(inputTimeout);
|
Ember.run.cancel(inputTimeout);
|
||||||
|
|
||||||
$(this).off('keypress.autocomplete')
|
$(this).off('keyup.autocomplete')
|
||||||
.off('keydown.autocomplete')
|
.off('keydown.autocomplete')
|
||||||
.off('paste.autocomplete')
|
.off('paste.autocomplete')
|
||||||
.off('click.autocomplete');
|
.off('click.autocomplete');
|
||||||
@ -247,7 +247,15 @@ export default function(options) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const SKIP = "skip";
|
||||||
|
var prevTerm = null;
|
||||||
|
|
||||||
const dataSource = (term, opts) => {
|
const dataSource = (term, opts) => {
|
||||||
|
if (prevTerm === term) {
|
||||||
|
return SKIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
prevTerm = term;
|
||||||
if (term.length !== 0 && term.trim().length === 0) {
|
if (term.length !== 0 && term.trim().length === 0) {
|
||||||
closeAutocomplete();
|
closeAutocomplete();
|
||||||
return null;
|
return null;
|
||||||
@ -256,9 +264,9 @@ export default function(options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var updateAutoComplete = function(r) {
|
const updateAutoComplete = function(r) {
|
||||||
|
|
||||||
if (completeStart === null) return;
|
if (completeStart === null || r === SKIP) return;
|
||||||
|
|
||||||
if (r && r.then && typeof(r.then) === "function") {
|
if (r && r.then && typeof(r.then) === "function") {
|
||||||
if (div) {
|
if (div) {
|
||||||
@ -309,21 +317,21 @@ export default function(options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$(this).on('keypress.autocomplete', function(e) {
|
$(this).on('keyup.autocomplete', function(e) {
|
||||||
var caretPosition, term;
|
|
||||||
|
|
||||||
// keep hunting backwards till you hit a the @ key
|
var caretPosition = Discourse.Utilities.caretPosition(me[0]);
|
||||||
if (options.key && e.which === options.key.charCodeAt(0)) {
|
|
||||||
caretPosition = Discourse.Utilities.caretPosition(me[0]);
|
if (options.key && completeStart === null && caretPosition > 0) {
|
||||||
var prevChar = me.val().charAt(caretPosition - 1);
|
var key = me[0].value[caretPosition-1];
|
||||||
|
if (key === options.key) {
|
||||||
|
var prevChar = me.val().charAt(caretPosition-2);
|
||||||
if (checkTriggerRule() && (!prevChar || allowedLettersRegex.test(prevChar))) {
|
if (checkTriggerRule() && (!prevChar || allowedLettersRegex.test(prevChar))) {
|
||||||
completeStart = completeEnd = caretPosition;
|
completeStart = completeEnd = caretPosition-1;
|
||||||
updateAutoComplete(dataSource("", options));
|
updateAutoComplete(dataSource("", options));
|
||||||
}
|
}
|
||||||
} else if ((completeStart !== null) && (e.charCode !== 0)) {
|
}
|
||||||
caretPosition = Discourse.Utilities.caretPosition(me[0]);
|
} else if (completeStart !== null) {
|
||||||
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
var term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
||||||
term += String.fromCharCode(e.charCode);
|
|
||||||
updateAutoComplete(dataSource(term, options));
|
updateAutoComplete(dataSource(term, options));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -336,7 +344,7 @@ export default function(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(options.allowAny){
|
if(options.allowAny){
|
||||||
// saves us wiring up a change event as well, keypress is while its pressed
|
// saves us wiring up a change event as well
|
||||||
|
|
||||||
Ember.run.cancel(inputTimeout);
|
Ember.run.cancel(inputTimeout);
|
||||||
inputTimeout = Ember.run.later(function(){
|
inputTimeout = Ember.run.later(function(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user