Merge pull request #235 from tms/autocomplete-right-away

Tweak autocomplete/caret_position logic to not exclude the index 0 case
This commit is contained in:
Sam 2013-02-23 19:05:23 -08:00
commit d42a87ec8a
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);