Skip to content

Fixed: Preserve horizontal pan and zoom when scrolling - #572

Merged
ahankinson merged 1 commit into
DDMAL:developfrom
etosphere:fix/preserve-horizontal-pan
Oct 5, 2026
Merged

ahankinson merged 1 commit into
DDMAL:developfrom
etosphere:fix/preserve-horizontal-pan

Conversation

@etosphere

@etosphere etosphere commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

After zooming in and dragging a canvas horizontally, scrolling with the mouse wheel or trackpad snaps it back to the horizontal center. Dragging the scrollbar does the same.

See #569.

Cause

  • handleWheel set the new center's x to the column middle (getCenterX()), then called recenterBoundsX().
  • clampTop/clampBottom also panned to getCenterX() when the view reached the first or last page, which also blocked dragging sideways at those limits.
  • The scrollbar used scrollToOffset, which fits the full layout width. That recenters x and resets any zoom past fit-width.

Fix

  • The wheel handler and the scrollbar keep the current x and change only y.
  • The clamps keep the target x (getCenter(false)). OSD raises pan for an animated drag step before the view moves, so using the current x would drop that step's horizontal movement.

Test

The new test covers the wheel, a scrollbar thumb drag, and a two-step animated pan against the top limit. It fails on develop and when the clamps use the current x. It waits for the zoom animation to finish because Diva recenters once after the first animation following load. The two-step pan makes the clamp run while a horizontal pan is still animating.

Summary by CodeRabbit

  • Bug Fixes
    • Scrolling and scrollbar interactions now preserve the viewer’s zoom and horizontal position.
    • Dragging the viewer after scrolling changes the horizontal position without shifting the vertical position.

The wheel handler and the top and bottom limit clamps recentered the
viewport horizontally, so a zoomed-in canvas that had been dragged
sideways jumped back to the middle as soon as it was scrolled. The
scrollbar refit the layout width instead, which also recentered the
viewport and, when zoomed in past the page width, reset the zoom.

Keep the horizontal position when scrolling with the wheel or the
scrollbar. The clamps keep the target x because OpenSeadragon raises
the pan event for an animated drag step before the view moves; the
current x would drop that step's horizontal movement at the limits.

Refs DDMAL#569
@etosphere
etosphere requested a review from ahankinson October 5, 2026 04:10
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: f074d900-deb5-41c7-8f34-247f033e2d42
📥 Commits

Reviewing files that changed from the base of the PR and between 159dd09 and a6cd642.

📒 Files selected for processing (2)
  • browser-tests/public-api.spec.ts
  • src/viewer-element.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

Wheel scrolling, top and bottom clamping, and scrollbar interactions now preserve the viewport’s current horizontal centre. Browser tests check that vertical scrolling preserves horizontal position and zoom, and that panning after scrolling changes horizontal position.

Changes

Viewport scrolling

Layer / File(s) Summary
Preserve viewport position during scrolling
src/viewer-element.ts, browser-tests/public-api.spec.ts
Wheel scrolling, top and bottom clamping, and scrollbar interactions preserve the horizontal centre. Scrollbar interactions preserve zoom. Browser tests check vertical movement, horizontal position, and zoom.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to a6cd6

The scrolling change has no identified issue that needs resolution before merge; normal checks remain appropriate.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: preserving horizontal pan and zoom during scrolling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ahankinson ahankinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great, thanks!!

@ahankinson
ahankinson merged commit ae4254c into DDMAL:develop Oct 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants