publisher does inline mentions and sets the cursor to the end of the newly inserted result

This commit is contained in:
danielvincent 2011-02-07 10:28:22 -08:00 committed by Raphael Sofaer
parent 3efc31c68f
commit 6eafd73d2c
2 changed files with 6 additions and 7 deletions

View file

@ -278,7 +278,6 @@ $.Autocompleter = function(input, options) {
};
function hideResultsNow() {
var wasVisible = select.visible();
select.hide();
clearTimeout(timeout);
stopLoading();
@ -298,9 +297,6 @@ $.Autocompleter = function(input, options) {
}
);
}
if (wasVisible)
// position cursor at end of input field
$.Autocompleter.Selection(input, input.value.length, input.value.length);
};
function receiveData(q, data) {
@ -390,6 +386,9 @@ $.Autocompleter.defaults = {
resultsClass: "ac_results",
loadingClass: "ac_loading",
onSelect: function(input, data, formatted){
if (select.visible())
// position cursor at end of input field
$.Autocompleter.Selection(input, input.value.length, input.value.length);
input.val(formatted);
},
minChars: 1,

View file

@ -60,7 +60,7 @@ var Publisher = {
onSelect : function(visibleInput, data, formatted) {
var visibleCursorIndex = visibleInput[0].selectionStart;
var visibleLoc = Publisher.autocompletion.addMentionToInput(visibleInput, visibleCursorIndex, formatted);
$.Autocompleter.Selection(visibleInput[0], visibleLoc[1], visibleLoc[1]);
var hiddenCursorIndex = visibleCursorIndex + Publisher.autocompletion.mentionList.offsetFrom(visibleCursorIndex);
var hiddenLoc = Publisher.autocompletion.addMentionToInput(Publisher.hiddenInput(), hiddenCursorIndex, Publisher.autocompletion.hiddenMentionFromPerson(data));
@ -126,13 +126,13 @@ var Publisher = {
var stringEnd = inputContent.slice(stringLoc[1]);
input.val(stringStart + formatted + stringEnd);
return [stringStart.length, stringStart.length + stringLoc[1]]
return [stringStart.length, stringStart.length + formatted.length]
},
findStringToReplace: function(value, cursorIndex){
var atLocation = value.lastIndexOf('@', cursorIndex);
if(atLocation == -1){return [0,0];}
var nextAt = value.indexOf(' @', cursorIndex+1);
var nextAt = cursorIndex//value.indexOf(' @', cursorIndex+1);
if(nextAt == -1){nextAt = value.length;}
return [atLocation, nextAt];