Tweak autocomplete/caret_position logic to not exclude the index 0 case

This commit is contained in:
tms 2013-02-22 23:47:23 -05:00
parent 7f08765ba7
commit 3a0227f868
2 changed files with 5 additions and 5 deletions

View file

@ -126,7 +126,7 @@
});
};
updateAutoComplete = function(r) {
if (!completeStart) return;
if (completeStart === null) return;
autocompleteOptions = r;
if (!r || r.length === 0) {
@ -197,7 +197,7 @@
if (e.which === 16) {
return;
}
if ((!completeStart) && e.which === 8 && options.key) {
if ((completeStart === null) && e.which === 8 && options.key) {
c = Discourse.Utilities.caretPosition(me[0]);
next = me[0].value[c];
nextIsGood = next === void 0 || /\s/.test(next);
@ -222,13 +222,13 @@
}
}
if (e.which === 27) {
if (completeStart) {
if (completeStart !== null) {
closeAutocomplete();
return false;
}
return true;
}
if (completeStart) {
if (completeStart !== null) {
caretPosition = Discourse.Utilities.caretPosition(me[0]);
/* If we've backspaced past the beginning, cancel unless no key
*/

View file

@ -70,7 +70,7 @@
});
before = void 0;
after = void 0;
pos = options && options.pos ? options.pos : getCaret(textarea[0]);
pos = options && (options.pos || options.pos === 0) ? options.pos : getCaret(textarea[0]);
val = textarea.val().replace("\r", "");
if (options && options.key) {
val = val.substring(0, pos) + options.key + val.substring(pos);