Skip to content

Commit

Permalink
FIX: ensures correct scroll position of textarea after autocomplete (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Jan 24, 2019
1 parent 671ff42 commit e5765fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Expand Up @@ -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());
}
});
}

Expand Down
17 changes: 15 additions & 2 deletions app/assets/javascripts/discourse/components/d-editor.js.es6
Expand Up @@ -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;
},
Expand Down Expand Up @@ -416,6 +420,7 @@ export default Ember.Component.extend({
key: ":",
afterComplete(text) {
self.set("value", text);
self._focusTextArea();
},

onKeyUp(text, cp) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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")) {
Expand All @@ -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 {
Expand Down

0 comments on commit e5765fe

Please sign in to comment.