Skip to content

Zoom viewport-centre anchoring (follow-up to #33, stacked on #34)#38

Draft
andrewtheart wants to merge 2 commits into
FrozenAssassine:masterfrom
andrewtheart:feat/zoom-viewport-centre-anchor
Draft

Zoom viewport-centre anchoring (follow-up to #33, stacked on #34)#38
andrewtheart wants to merge 2 commits into
FrozenAssassine:masterfrom
andrewtheart:feat/zoom-viewport-centre-anchor

Conversation

@andrewtheart

Copy link
Copy Markdown
Contributor

Stacked on #34. Builds on the pixel-offset scroll seam, so until #34 merges this PR's diff also
includes #34's files. Please review #34 first; I'll rebase onto master once it lands. Draft for that reason.

Follow-up to #33: zoom viewport-centre anchoring

A small quality-of-life follow-up that builds directly on the #34 seam.

Problem

When you zoom (Ctrl+wheel / pinch / a zoom command), the font size changes but the raw pixel scroll offset
stays the same — so the row under your eyes drifts, because the same pixel offset now maps to a different
row once the line height changes. Zooming feels like the document slides around.

Fix

ZoomManager.UpdateZoom now re-anchors the pixel scroll seam so the document row under the vertical
viewport centre stays stationary
across the zoom. The horizontal axis scales by the font-size ratio so the
left-most visible column stays roughly put too.

The line height is ZoomedFontSize + LineSpacingPadding, and the format is only rebuilt on the next draw, so
the old line height is snapshotted at the top of UpdateZoom before the new font size is computed. The
arithmetic is extracted into a pure ZoomScrollAnchor (vertical centre-row preservation + horizontal ratio
scale) and unit-tested; ZoomManager just wires it to the offset source.

Changes

  • new Core/ZoomScrollAnchor.cs — pure anchor math (+ ZoomScrollAnchorTests).
  • Core/ZoomManager.cs — snapshot old line height, call AnchorScrollAcrossZoom through the offset source
    (adds a ScrollManager dependency).
  • Core/TextLayoutManager.cs — names the line-spacing padding as LineSpacingPadding (was an inline + 2)
    so the post-zoom line height can be computed before the format rebuilds.

Verification

Behavior is unchanged except the anchor (guarded to no-op before the first real layout). Library + test
project build clean (x64).

Introduce a small IScrollOffsetSource abstraction so the editor scroll position is expressed in pixels rather than legacy scrollbar units (SingleLineHeight / DefaultVerticalScrollSensitivity). ScrollManager routes every offset read/write through it; the ScrollBarOffsetSource adapter backs it with the existing two ScrollBar primitives and does the pixel<->scrollbar-unit conversion internally (ScrollOffsetMath). Behavior is unchanged. Foundation for word-wrap scrolling, long-line horizontal virtualization and diagonal 2-axis touchpad scrolling (FrozenAssassine#33). Adds ScrollOffsetMathTests.
ZoomManager.UpdateZoom re-anchors the pixel offset seam so the document row under the vertical viewport centre stays stationary across a font-size change instead of drifting; horizontal scales by the font-size ratio. Pure math extracted to ZoomScrollAnchor + unit tests. Follow-up to FrozenAssassine#33, builds on FrozenAssassine#34.
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.

1 participant