mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
reduce number of times caretPosition() is called
This commit is contained in:
@ -259,19 +259,20 @@ export default function(options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(this).keypress(function(e) {
|
$(this).keypress(function(e) {
|
||||||
var caretPosition = Discourse.Utilities.caretPosition(me[0]),
|
var caretPosition, term;
|
||||||
term;
|
|
||||||
|
|
||||||
if (!options.key) return;
|
if (!options.key) return;
|
||||||
|
|
||||||
// keep hunting backwards till you hit a the @ key
|
// keep hunting backwards till you hit a the @ key
|
||||||
if (e.which === options.key.charCodeAt(0)) {
|
if (e.which === options.key.charCodeAt(0)) {
|
||||||
|
caretPosition = Discourse.Utilities.caretPosition(me[0]);
|
||||||
var prevChar = me.val().charAt(caretPosition - 1);
|
var prevChar = me.val().charAt(caretPosition - 1);
|
||||||
if (!prevChar || /\s/.test(prevChar)) {
|
if (!prevChar || /\s/.test(prevChar)) {
|
||||||
completeStart = completeEnd = caretPosition;
|
completeStart = completeEnd = caretPosition;
|
||||||
updateAutoComplete(options.dataSource(""));
|
updateAutoComplete(options.dataSource(""));
|
||||||
}
|
}
|
||||||
} else if ((completeStart !== null) && (e.charCode !== 0)) {
|
} else if ((completeStart !== null) && (e.charCode !== 0)) {
|
||||||
|
caretPosition = Discourse.Utilities.caretPosition(me[0]),
|
||||||
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
||||||
term += String.fromCharCode(e.charCode);
|
term += String.fromCharCode(e.charCode);
|
||||||
updateAutoComplete(options.dataSource(term));
|
updateAutoComplete(options.dataSource(term));
|
||||||
|
Reference in New Issue
Block a user