Skip to content

Commit 587398a

Browse files
authored
Scroll element should scroll into view after "Enter" key pressed (T1074082) (#37)
(cherry picked from commit b17133d)
1 parent fbaed83 commit 587398a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

modules/keyboard.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ class Keyboard extends Module {
362362
this.quill.updateContents(delta, Quill.sources.USER);
363363
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
364364
this.quill.focus();
365+
context.line.domNode.scrollIntoView(false);
365366

366367
Object.keys(context.format).forEach(name => {
367368
if (lineFormats[name] != null) return;

test/functional/epic.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ describe('quill', function() {
229229
html = await page.$eval('.ql-editor', e => e.innerHTML);
230230
expect(html).toEqual(`<p>12 </p><p>${EMBED} 34</p>`);
231231

232+
const windowScrollY = await page.$eval('html', e => e.scrollTop);
233+
await page.click('#content');
234+
await page.keyboard.press('Enter');
235+
await page.keyboard.press('Enter');
236+
await page.keyboard.press('Enter');
237+
const actualWindowScrollY = await page.$eval('html', e => e.scrollTop);
238+
239+
expect(actualWindowScrollY).toBeGreaterThan(windowScrollY);
240+
232241
await browser.close();
233242
});
234243
});

test/functional/example/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<button id="italic">Italic</button>
1616
<button id="header">Header</button>
1717
<button id="embed">Insert embed</button>
18+
<button id="content">Insert much more content</button>
1819

1920
<div id="editor"></div>
2021
</div>
@@ -62,5 +63,18 @@
6263
editor.focus();
6364
editor.setSelection(4, 0);
6465
});
66+
67+
document
68+
.getElementById('content')
69+
.addEventListener('click', () => {
70+
const content = new Array (150).fill('lorem\n').join('');
71+
72+
editor.setContents({
73+
ops: [{ insert: content }]
74+
});
75+
76+
editor.focus();
77+
editor.setSelection(editor.getLength() - 1, 0);
78+
});
6579
</script>
6680
</html>

0 commit comments

Comments
 (0)