Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,41 @@ export class PresentationEditor extends EventEmitter {
}
}

/**
* Scrolls a specific page into view.
*
* @param pageNumber - One-based page number to scroll to (e.g., 1 for first page)
* @param scrollBehavior - Scroll behavior ('auto' | 'smooth'). Defaults to 'smooth'.
* @returns True if the page was scrolled to, false if layout not available or invalid page
*
* @example
* ```typescript
* // Smooth scroll to first page
* presentationEditor.scrollToPage(1);
*
* // Instant scroll to page 5
* presentationEditor.scrollToPage(5, 'auto');
* ```
*/
scrollToPage(pageNumber: number, scrollBehavior: ScrollBehavior = 'smooth'): boolean {
const layout = this.#layoutState.layout;
if (!layout) return false;

// Convert 1-based page number to 0-based index
const pageIndex = pageNumber - 1;

// Clamp to valid page range
const maxPage = layout.pages.length - 1;
if (pageIndex < 0 || pageIndex > maxPage) return false;

const pageEl = getPageElementByIndex(this.#viewportHost, pageIndex);
if (pageEl) {
pageEl.scrollIntoView({ block: 'start', inline: 'nearest', behavior: scrollBehavior });
return true;
}
return false;
Comment on lines +2008 to +2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scroll even when target page isn't mounted

This implementation only calls scrollIntoView if getPageElementByIndex returns an element, and otherwise returns false without changing scroll. When page virtualization is enabled, off‑screen pages are often not mounted in the DOM, so getPageElementByIndex will return null even for valid pages; in that case scrollToPage cannot bring the page into view at all. This makes the new public API fail for any page outside the mounted window. Consider using the same approach as other navigation helpers (e.g., scroll to the computed y‑position and/or wait for mount) so virtualized pages can be reached.

Useful? React with 👍 / 👎.

}

/**
* Get document position from viewport coordinates (header/footer-aware).
*
Expand Down