Skip to content

Commit 1bb6107

Browse files
committed
test(enter): cover scroll-to-follow-cursor on Enter at the bottom
Regression test for the scenario in #1300 (Enter near the bottom scrolls the editor to follow the caret); verified working on the current version. Refs #1300
1 parent 749c068 commit 1bb6107

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
Jodit.make('#editor', { nonce: 'r4nd0m' });
2525
```
2626

27+
#### :house: Internal
28+
29+
- **Enter tests**: added a regression test asserting that pressing Enter with the caret at the bottom of a scrollable editing area scrolls to follow the cursor (and does not scroll when the caret line is already visible). Covers the scenario from [#1300](https://github.com/xdan/jodit/issues/1300), which works on the current version.
30+
2731
## 4.12.37
2832

2933
#### :bug: Bug Fix

src/plugins/enter/enter.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,50 @@
55
*/
66

77
describe('Enter behavior Tests', function () {
8+
// https://github.com/xdan/jodit/issues/1300
9+
describe('Scroll after Enter', function () {
10+
const fill = editor => {
11+
const lines = [];
12+
for (let i = 0; i < 30; i += 1) {
13+
lines.push('<p>line ' + i + '</p>');
14+
}
15+
editor.value = lines.join('');
16+
};
17+
18+
it('Should scroll the editor to follow the cursor when Enter is pressed at the bottom', function () {
19+
const editor = getJodit({ height: 150 });
20+
fill(editor);
21+
22+
const area = editor.editor;
23+
24+
// sanity: the editing area is actually scrollable
25+
expect(area.scrollHeight).is.above(area.clientHeight);
26+
27+
editor.s.setCursorIn(area.querySelector('p:last-child'), false);
28+
area.scrollTop = 0;
29+
30+
editor.execCommand('enter');
31+
32+
expect(area.scrollTop).is.above(0);
33+
});
34+
35+
it('Should not scroll when the caret line is already visible', function () {
36+
const editor = getJodit({ height: 150 });
37+
fill(editor);
38+
39+
const area = editor.editor;
40+
const mid = area.querySelectorAll('p')[15];
41+
42+
editor.s.setCursorIn(mid, false);
43+
area.scrollTop = mid.offsetTop;
44+
const before = area.scrollTop;
45+
46+
editor.execCommand('enter');
47+
48+
expect(area.scrollTop).equals(before);
49+
});
50+
});
51+
852
describe('Enter key', function () {
953
describe('Enter BR', function () {
1054
it('Should simple insert BR element', function () {

0 commit comments

Comments
 (0)