FIX: ensures correct scroll position of textarea after autocomplete (#6942)

FIX: ensures correct scroll position of textarea after autocomplete (#6942)

diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6
index c84ebc9..059bddb 100644
--- a/app/assets/javascripts/discourse/components/composer-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6
@@ -163,7 +163,11 @@ export default Ember.Component.extend({
             includeMentionableGroups: true
           }),
         key: "@",
-        transformComplete: v => v.username || v.name
+        transformComplete: v => v.username || v.name,
+        afterComplete() {
+          // ensures textarea scroll position is correct
+          Ember.run.scheduleOnce("afterRender", () => $input.blur().focus());
+        }
       });
     }
 
diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6
index 04db1ef..fca09f4 100644
--- a/app/assets/javascripts/discourse/components/d-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/d-editor.js.es6
@@ -385,10 +385,14 @@ export default Ember.Component.extend({
 
   _applyCategoryHashtagAutocomplete() {
     const siteSettings = this.siteSettings;
+    const self = this;
 
     this.$(".d-editor-input").autocomplete({
       template: findRawTemplate("category-tag-autocomplete"),
       key: "#",
+      afterComplete() {
+        self._focusTextArea();
+      },
       transformComplete(obj) {
         return obj.text;
       },
@@ -416,6 +420,7 @@ export default Ember.Component.extend({
       key: ":",
       afterComplete(text) {
         self.set("value", text);
+        self._focusTextArea();
       },
 
       onKeyUp(text, cp) {
@@ -722,7 +727,7 @@ export default Ember.Component.extend({
     $textarea.prop("selectionStart", (pre + text).length + 2);
     $textarea.prop("selectionEnd", (pre + text).length + 2);
 
-    Ember.run.scheduleOnce("afterRender", () => $textarea.focus());
+    this._focusTextArea();
   },
 
   _addText(sel, text, options) {
@@ -747,7 +752,8 @@ export default Ember.Component.extend({
     $textarea.val(value);
     $textarea.prop("selectionStart", insert.length);
     $textarea.prop("selectionEnd", insert.length);
-    Ember.run.scheduleOnce("afterRender", () => $textarea.focus());
+
+    this._focusTextArea();
   },
 
   _extractTable(text) {
@@ -838,6 +844,12 @@ export default Ember.Component.extend({
     }
   },
 
+  // ensures textarea scroll position is correct
+  _focusTextArea() {
+    const $textarea = this.$("textarea.d-editor-input");
+    Ember.run.scheduleOnce("afterRender", () => $textarea.blur().focus());
+  },
+
   actions: {
     emoji() {
       if (this.get("disabled")) {
@@ -850,6 +862,7 @@ export default Ember.Component.extend({
     emojiSelected(code) {
       let selected = this._getSelected();
       const captures = selected.pre.match(/\B:(\w*)$/);
+
       if (_.isEmpty(captures)) {
         this._addText(selected, `:${code}:`);
       } else {

GitHub sha: e5765fe1