Skip to content

Commit

Permalink
Fix bug in scrolling
Browse files Browse the repository at this point in the history
FIX: Fix an issue where scrolling down to a range higher than the viewport
could in some situations fail to scroll to the proper position.
  • Loading branch information
marijnh committed Feb 28, 2025
1 parent 441d528 commit 683f9e1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ export function scrollRectIntoView(dom: HTMLElement, rect: Rect, side: -1 | 1,
let moveX = 0, moveY = 0
if (y == "nearest") {
if (rect.top < bounding.top) {
moveY = -(bounding.top - rect.top + yMargin)
moveY = rect.top - (bounding.top + yMargin)
if (side > 0 && rect.bottom > bounding.bottom + moveY)
moveY = rect.bottom - bounding.bottom + moveY + yMargin
moveY = rect.bottom - bounding.bottom + yMargin
} else if (rect.bottom > bounding.bottom) {
moveY = rect.bottom - bounding.bottom + yMargin
if (side < 0 && (rect.top - moveY) < bounding.top)
moveY = -(bounding.top + moveY - rect.top + yMargin)
moveY = rect.top - (bounding.top + yMargin)
}
} else {
let rectHeight = rect.bottom - rect.top, boundingHeight = bounding.bottom - bounding.top
Expand All @@ -156,13 +156,13 @@ export function scrollRectIntoView(dom: HTMLElement, rect: Rect, side: -1 | 1,
}
if (x == "nearest") {
if (rect.left < bounding.left) {
moveX = -(bounding.left - rect.left + xMargin)
moveX = rect.left - (bounding.left + xMargin)
if (side > 0 && rect.right > bounding.right + moveX)
moveX = rect.right - bounding.right + moveX + xMargin
moveX = rect.right - bounding.right + xMargin
} else if (rect.right > bounding.right) {
moveX = rect.right - bounding.right + xMargin
if (side < 0 && rect.left < bounding.left + moveX)
moveX = -(bounding.left + moveX - rect.left + xMargin)
moveX = rect.left - (bounding.left + xMargin)
}
} else {
let targetLeft =
Expand Down

0 comments on commit 683f9e1

Please sign in to comment.