-
Notifications
You must be signed in to change notification settings - Fork 150
fix(presentation): keep virtualized pages in sync with host scroll #3488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tupizz
wants to merge
1
commit into
main
Choose a base branch
from
tadeu/sd-3230-virtualized-pages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
tests/behavior/tests/virtualization/blocked-scroll-event.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { test, expect } from '../../fixtures/superdoc.js'; | ||
|
|
||
| test.use({ config: { toolbar: 'none', previewScroll: true, blockPreviewScrollEvents: true } }); | ||
|
|
||
| async function generateLongDocument(page: any, paragraphCount = 200): Promise<void> { | ||
| await page.evaluate((count: number) => { | ||
| const editor = (window as any).editor; | ||
| const { state } = editor; | ||
| const { schema } = state; | ||
|
|
||
| const paragraphs: any[] = []; | ||
| for (let i = 0; i < count; i++) { | ||
| const text = schema.text( | ||
| `SD-3230 paragraph ${i + 1}. ` + | ||
| 'This document is intentionally long enough to require a virtualized page window. ' + | ||
| 'The visible pages should update when the scroll owner moves.', | ||
| ); | ||
| const run = schema.nodes.run.create(null, text); | ||
| paragraphs.push(schema.nodes.paragraph.create(null, run)); | ||
| } | ||
|
|
||
| const doc = schema.nodes.doc.create(null, paragraphs); | ||
| const tr = state.tr.replaceWith(0, state.doc.content.size, doc.content); | ||
| editor.view.dispatch(tr); | ||
| }, paragraphCount); | ||
| } | ||
|
|
||
| async function jumpPastInitialVirtualWindow(page: any): Promise<void> { | ||
| await page.evaluate(() => { | ||
| const editor = document.querySelector('.superdoc-viewport') ?? document.querySelector('#editor'); | ||
| let scrollOwner: HTMLElement | null = editor as HTMLElement; | ||
|
|
||
| while (scrollOwner && scrollOwner !== document.documentElement) { | ||
| if (scrollOwner.scrollHeight > scrollOwner.clientHeight + 10) break; | ||
| scrollOwner = scrollOwner.parentElement; | ||
| } | ||
|
|
||
| if (!scrollOwner || scrollOwner === document.documentElement) { | ||
| throw new Error('Expected a SuperDoc scroll owner for the virtualization regression test.'); | ||
| } | ||
|
|
||
| scrollOwner.scrollTop = Math.floor(scrollOwner.clientHeight * 8); | ||
| }); | ||
| } | ||
|
|
||
| async function getVirtualizedViewportState(page: any): Promise<{ | ||
| scrollTop: number; | ||
| mountedPages: number[]; | ||
| visibleText: string; | ||
| }> { | ||
| return page.evaluate(() => { | ||
| const editor = document.querySelector('.superdoc-viewport') ?? document.querySelector('#editor'); | ||
| let scrollOwner: HTMLElement | null = editor as HTMLElement; | ||
|
|
||
| while (scrollOwner && scrollOwner !== document.documentElement) { | ||
| if (scrollOwner.scrollHeight > scrollOwner.clientHeight + 10) break; | ||
| scrollOwner = scrollOwner.parentElement; | ||
| } | ||
|
|
||
| if (!scrollOwner || scrollOwner === document.documentElement) { | ||
| throw new Error('Expected a SuperDoc scroll owner for the virtualization regression test.'); | ||
| } | ||
|
|
||
| const mountedPages = Array.from(document.querySelectorAll('.superdoc-page[data-page-index]')) | ||
| .map((pageEl) => Number((pageEl as HTMLElement).dataset.pageIndex)) | ||
| .sort((a, b) => a - b); | ||
|
|
||
| const ownerRect = scrollOwner.getBoundingClientRect(); | ||
| const visibleText = Array.from(document.querySelectorAll('.superdoc-page[data-page-index]')) | ||
| .filter((pageEl) => { | ||
| const rect = pageEl.getBoundingClientRect(); | ||
| return rect.bottom > ownerRect.top && rect.top < ownerRect.bottom; | ||
| }) | ||
| .map((pageEl) => pageEl.textContent?.trim() ?? '') | ||
| .join('\n') | ||
| .trim(); | ||
|
|
||
| return { | ||
| scrollTop: scrollOwner.scrollTop, | ||
| mountedPages, | ||
| visibleText, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| test('virtualized pages follow a host scroll owner that stops scroll propagation', async ({ superdoc }) => { | ||
| await generateLongDocument(superdoc.page); | ||
| await superdoc.waitForStable(2000); | ||
|
|
||
| await jumpPastInitialVirtualWindow(superdoc.page); | ||
| await superdoc.waitForStable(500); | ||
|
|
||
| const state = await getVirtualizedViewportState(superdoc.page); | ||
|
|
||
| expect(state.scrollTop).toBeGreaterThan(0); | ||
| expect(Math.min(...state.mountedPages)).toBeGreaterThan(0); | ||
| expect(state.visibleText).toContain('SD-3230 paragraph'); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.