diff --git a/public/javascripts/jquery.autocomplete-custom.js b/public/javascripts/jquery.autocomplete-custom.js index afb50fa51..7e2eba156 100644 --- a/public/javascripts/jquery.autocomplete-custom.js +++ b/public/javascripts/jquery.autocomplete-custom.js @@ -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, diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js index 0e79c3a3c..209a755f5 100644 --- a/public/javascripts/publisher.js +++ b/public/javascripts/publisher.js @@ -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];