Skip to content

Commit

Permalink
FIX: On chrome, focusing on a recently changed textarea would scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Dec 29, 2015
1 parent a42826f commit fd6bbc6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/assets/javascripts/discourse/components/d-editor.js.es6
Expand Up @@ -317,12 +317,15 @@ export default Ember.Component.extend({

_selectText(from, length) {
Ember.run.scheduleOnce('afterRender', () => {
const textarea = this.$('textarea.d-editor-input')[0];
const $textarea = this.$('textarea.d-editor-input');
const textarea = $textarea[0];
const oldScrollPos = $textarea.scrollTop();
if (!this.capabilities.isIOS) {
textarea.focus();
$textarea.focus();
}
textarea.selectionStart = from;
textarea.selectionEnd = textarea.selectionStart + length;
$textarea.scrollTop(oldScrollPos);
});
},

Expand Down
20 changes: 20 additions & 0 deletions test/javascripts/components/d-editor-test.js.es6
Expand Up @@ -516,6 +516,26 @@ testCase(`rule with a selection`, function(assert, textarea) {
});
});

testCase(`doesn't jump to bottom with long text`, function(assert, textarea) {

let longText = 'hello world.';
for (let i=0; i<8; i++) {
longText = longText + longText;
}
this.set('value', longText);

andThen(() => {
$(textarea).scrollTop(0);
textarea.selectionStart = 3;
textarea.selectionEnd = 3;
});

click('button.bold');
andThen(() => {
assert.equal($(textarea).scrollTop(), 0, 'it stays scrolled up');
});
});

componentTest('emoji', {
template: '{{d-editor value=value}}',
setup() {
Expand Down

0 comments on commit fd6bbc6

Please sign in to comment.