Merge pull request #332 from mvanhorn/fix/scroll-direction-pixels

fix(page-controller): apply scroll direction to pixels parameter
This commit is contained in:
Simon
2026-04-02 18:36:42 +08:00
committed by GitHub
2 changed files with 7 additions and 21 deletions

View File

@@ -322,11 +322,11 @@ export class PageController extends EventTarget {
this.assertIndexed() this.assertIndexed()
const scrollAmount = pixels ?? numPages * (down ? 1 : -1) * window.innerHeight const scrollAmount = (pixels ?? numPages * window.innerHeight) * (down ? 1 : -1)
const element = index !== undefined ? getElementByIndex(this.selectorMap, index) : null const element = index !== undefined ? getElementByIndex(this.selectorMap, index) : null
const message = await scrollVertically(down, scrollAmount, element) const message = await scrollVertically(scrollAmount, element)
return { return {
success: true, success: true,
@@ -357,7 +357,7 @@ export class PageController extends EventTarget {
const element = index !== undefined ? getElementByIndex(this.selectorMap, index) : null const element = index !== undefined ? getElementByIndex(this.selectorMap, index) : null
const message = await scrollHorizontally(right, scrollAmount, element) const message = await scrollHorizontally(scrollAmount, element)
return { return {
success: true, success: true,

View File

@@ -274,14 +274,7 @@ export async function scrollIntoViewIfNeeded(element: Element) {
} }
} }
/** export async function scrollVertically(scroll_amount: number, element?: HTMLElement | null) {
* @private Internal method, subject to change at any time.
*/
export async function scrollVertically(
down: boolean,
scroll_amount: number,
element?: HTMLElement | null
) {
// Element-specific scrolling if element is provided // Element-specific scrolling if element is provided
if (element) { if (element) {
const targetElement = element const targetElement = element
@@ -405,14 +398,7 @@ export async function scrollVertically(
} }
} }
/** export async function scrollHorizontally(scroll_amount: number, element?: HTMLElement | null) {
* @private Internal method, subject to change at any time.
*/
export async function scrollHorizontally(
right: boolean,
scroll_amount: number,
element?: HTMLElement | null
) {
// Element-specific scrolling if element is provided // Element-specific scrolling if element is provided
if (element) { if (element) {
const targetElement = element const targetElement = element
@@ -421,7 +407,7 @@ export async function scrollHorizontally(
let scrolledElement: HTMLElement | null = null let scrolledElement: HTMLElement | null = null
let scrollDelta = 0 let scrollDelta = 0
let attempts = 0 let attempts = 0
const dx = right ? scroll_amount : -scroll_amount const dx = scroll_amount
while (currentElement && attempts < 10) { while (currentElement && attempts < 10) {
const computedStyle = window.getComputedStyle(currentElement) const computedStyle = window.getComputedStyle(currentElement)
@@ -469,7 +455,7 @@ export async function scrollHorizontally(
// Page-level scrolling (default or fallback) // Page-level scrolling (default or fallback)
const dx = right ? scroll_amount : -scroll_amount const dx = scroll_amount
const bigEnough = (el: HTMLElement) => el.clientWidth >= window.innerWidth * 0.5 const bigEnough = (el: HTMLElement) => el.clientWidth >= window.innerWidth * 0.5
const canScroll = (el: HTMLElement | null) => const canScroll = (el: HTMLElement | null) =>
el && el &&