mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 00:57:55 +08:00
FIX: On chrome, focusing on a recently changed textarea would scroll
This commit is contained in:
parent
a42826f2ae
commit
fd6bbc69e2
app/assets/javascripts/discourse/components
test/javascripts/components
@ -317,12 +317,15 @@ export default Ember.Component.extend({
|
|||||||
|
|
||||||
_selectText(from, length) {
|
_selectText(from, length) {
|
||||||
Ember.run.scheduleOnce('afterRender', () => {
|
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) {
|
if (!this.capabilities.isIOS) {
|
||||||
textarea.focus();
|
$textarea.focus();
|
||||||
}
|
}
|
||||||
textarea.selectionStart = from;
|
textarea.selectionStart = from;
|
||||||
textarea.selectionEnd = textarea.selectionStart + length;
|
textarea.selectionEnd = textarea.selectionStart + length;
|
||||||
|
$textarea.scrollTop(oldScrollPos);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -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', {
|
componentTest('emoji', {
|
||||||
template: '{{d-editor value=value}}',
|
template: '{{d-editor value=value}}',
|
||||||
setup() {
|
setup() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user