|
| 1 | +import {expect, test} from "@playwright/test"; |
| 2 | +import {clearPadContent, goToNewPad} from "../helper/padHelper"; |
| 3 | + |
| 4 | +test.beforeEach(async ({page}) => { |
| 5 | + await goToNewPad(page); |
| 6 | +}); |
| 7 | + |
| 8 | +// Regression test for https://github.com/ether/etherpad/issues/4562 |
| 9 | +// PageDown failed to scroll when the cursor was on a very long wrapped line and |
| 10 | +// the following lines were also very long, because getVisibleLineRange returns |
| 11 | +// indices into rep.lines (logical lines) and collapsed to [n, n] — so the |
| 12 | +// advance count was 0 and both caret and scroll stayed put. |
| 13 | +test.describe('PageDown on consecutive long wrapped lines (#4562)', function () { |
| 14 | + test.describe.configure({retries: 2}); |
| 15 | + |
| 16 | + test('PageDown scrolls when three very long lines fill the viewport', async function ({page}) { |
| 17 | + await clearPadContent(page); |
| 18 | + |
| 19 | + const innerFrame = page.frame('ace_inner')!; |
| 20 | + |
| 21 | + // Insert three long lines via the editor directly — each ~2000 chars, which |
| 22 | + // wraps to many visual rows in the viewport. |
| 23 | + await innerFrame.evaluate(() => { |
| 24 | + const body = document.getElementById('innerdocbody')!; |
| 25 | + const longText = 'invisible '.repeat(200).trim(); |
| 26 | + body.innerHTML = ''; |
| 27 | + for (let i = 0; i < 3; i++) { |
| 28 | + const div = document.createElement('div'); |
| 29 | + div.textContent = `${i + 1} ${longText}`; |
| 30 | + body.appendChild(div); |
| 31 | + } |
| 32 | + // Trigger the editor to pick up the content |
| 33 | + body.dispatchEvent(new Event('input', {bubbles: true})); |
| 34 | + }); |
| 35 | + |
| 36 | + // Type a character at the end to make the editor register the long content |
| 37 | + // via its normal input path (the raw innerHTML edit above is just a scaffold). |
| 38 | + await page.keyboard.press('End'); |
| 39 | + await page.keyboard.type('!'); |
| 40 | + await page.waitForTimeout(300); |
| 41 | + |
| 42 | + // Move caret to start of pad |
| 43 | + await page.keyboard.down('Control'); |
| 44 | + await page.keyboard.press('Home'); |
| 45 | + await page.keyboard.up('Control'); |
| 46 | + await page.waitForTimeout(200); |
| 47 | + |
| 48 | + // Capture initial scroll position of the outer (scrollable) frame |
| 49 | + const outerFrame = page.frame('ace_outer')!; |
| 50 | + const before = await outerFrame.evaluate( |
| 51 | + () => (document.getElementById('outerdocbody') as HTMLElement).scrollTop || |
| 52 | + document.scrollingElement?.scrollTop || 0); |
| 53 | + |
| 54 | + // Press PageDown — the ace handler uses a 200ms setTimeout internally. |
| 55 | + await page.keyboard.press('PageDown'); |
| 56 | + await page.waitForTimeout(800); |
| 57 | + |
| 58 | + const after = await outerFrame.evaluate( |
| 59 | + () => (document.getElementById('outerdocbody') as HTMLElement).scrollTop || |
| 60 | + document.scrollingElement?.scrollTop || 0); |
| 61 | + |
| 62 | + // Either the viewport scrolled, or the caret advanced to a later logical line. |
| 63 | + const caretLine = await innerFrame.evaluate(() => { |
| 64 | + const sel = document.getSelection(); |
| 65 | + if (!sel || !sel.focusNode) return 0; |
| 66 | + let node = sel.focusNode as HTMLElement; |
| 67 | + while (node && node.tagName !== 'DIV') node = node.parentElement!; |
| 68 | + if (!node) return 0; |
| 69 | + const divs = Array.from(document.getElementById('innerdocbody')!.children); |
| 70 | + return divs.indexOf(node); |
| 71 | + }); |
| 72 | + |
| 73 | + // Pre-fix behavior (#4562): after == before AND caretLine === 0. |
| 74 | + // Fixed behavior: caret advances at least 1 logical line, or the viewport scrolls. |
| 75 | + expect(after > before || caretLine > 0).toBe(true); |
| 76 | + }); |
| 77 | +}); |
0 commit comments