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

View File

@ -70,7 +70,7 @@
}); });
before = void 0; before = void 0;
after = 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", ""); val = textarea.val().replace("\r", "");
if (options && options.key) { if (options && options.key) {
val = val.substring(0, pos) + options.key + val.substring(pos); val = val.substring(0, pos) + options.key + val.substring(pos);