diff --git a/app/assets/javascripts/discourse/lib/autocomplete.js.es6 b/app/assets/javascripts/discourse/lib/autocomplete.js.es6 index 5900968a5ef..c229d8f1768 100644 --- a/app/assets/javascripts/discourse/lib/autocomplete.js.es6 +++ b/app/assets/javascripts/discourse/lib/autocomplete.js.es6 @@ -285,11 +285,10 @@ export default function(options) { hOffset = 0; } else { pos = me.caretPosition({ - pos: completeStart, - key: options.key + pos: completeStart + 1 }); - hOffset = 27; + hOffset = 10; if (options.treatAsTextarea) vOffset = -32; } diff --git a/vendor/assets/javascripts/caret_position.js b/vendor/assets/javascripts/caret_position.js index 8a7b2e0616e..094d504d4b5 100644 --- a/vendor/assets/javascripts/caret_position.js +++ b/vendor/assets/javascripts/caret_position.js @@ -1,3 +1,6 @@ +// TODO: This code should be moved to lib, it was heavily modified by us over the years, and mostly written by us +// except for the little snippet from StackOverflow +// // http://stackoverflow.com/questions/263743/how-to-get-caret-position-in-textarea var clone, getCaret; getCaret = function(el) { @@ -19,7 +22,7 @@ getCaret = function(el) { clone = null; -$.fn.caret = function(){ +$.fn.caret = function() { return getCaret(this[0]); }; @@ -29,7 +32,22 @@ $.fn.caret = function(){ @module $.fn.caretPosition **/ $.fn.caretPosition = function(options) { - var after, before, getStyles, guard, html, important, insertSpaceAfterBefore, letter, makeCursor, p, pPos, pos, span, styles, textarea, val; + var after, + before, + getStyles, + guard, + html, + important, + insertSpaceAfterBefore, + letter, + makeCursor, + p, + pPos, + pos, + span, + styles, + textarea, + val; if (clone) { clone.remove(); } @@ -44,17 +62,15 @@ $.fn.caretPosition = function(options) { } }; - styles = getStyles(textarea[0]); - clone = $("