Zoom viewport-centre anchoring (follow-up to #33, stacked on #34)#38
Draft
andrewtheart wants to merge 2 commits into
Draft
Zoom viewport-centre anchoring (follow-up to #33, stacked on #34)#38andrewtheart wants to merge 2 commits into
andrewtheart wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.UpdateZoomnow re-anchors the pixel scroll seam so the document row under the verticalviewport 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, sothe old line height is snapshotted at the top of
UpdateZoombefore the new font size is computed. Thearithmetic is extracted into a pure
ZoomScrollAnchor(vertical centre-row preservation + horizontal ratioscale) and unit-tested;
ZoomManagerjust wires it to the offset source.Changes
Core/ZoomScrollAnchor.cs— pure anchor math (+ZoomScrollAnchorTests).Core/ZoomManager.cs— snapshot old line height, callAnchorScrollAcrossZoomthrough the offset source(adds a
ScrollManagerdependency).Core/TextLayoutManager.cs— names the line-spacing padding asLineSpacingPadding(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).