Word wrap (visual-row model) — step 3 of #33 (stacked on #34, #35)#37
Draft
andrewtheart wants to merge 3 commits into
Draft
Word wrap (visual-row model) — step 3 of #33 (stacked on #34, #35)#37andrewtheart wants to merge 3 commits into
andrewtheart wants to merge 3 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.
On files with pathologically long lines (minified JS/CSS/JSON, JSONL logs), the renderer joined every visible line into one multi-megabyte string and laid it out on every frame, causing horizontal-scroll stutter. TextRenderer.Draw now lays out only a sliced window of each visible line when a visible line exceeds 50k chars; ordinary files keep the untouched render path. The uniform slice window is re-aligned to document coordinates via HorizontalOffset + a per-line prefix sum, and the caret, click hit-testing and selection map through GetRenderedCharacterIndexForDocumentCharacter / GetDocumentCharacterIndexFromRenderedIndex / GetRenderedLayoutIndexForDocument (all no-ops when inactive). The window/index arithmetic is extracted into a WinUI-free HorizontalSliceMath with unit tests. Step 2 of FrozenAssassine#33.
Introduce word wrap on the previously no-wrap-only control. A document line can span multiple visual rows, so scrolling, caret, selection, click hit-testing and arrow navigation work in visual-row space via a WrapRowMetrics prefix-sum model (document line <-> visual row, with cheap incremental updates) and WrapGeometry pointer math, both pure and unit-tested. Excludes very-long-line wrapped-line virtualization (row count falls back to an estimate above 100k chars). Behavior is unchanged when WordWrap is false. Step 3 of FrozenAssassine#33.
This was referenced Jul 11, 2026
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.
Step 3 of the editor scroll/render series (#33)
Adds word wrap — the largest piece of the series. The control is currently hardcoded
CanvasWordWrapping.NoWrap; this introduces the visual-row model that makes wrapping work correctly withscrolling, the caret, selection, click hit-testing and arrow-key navigation.
Why a "visual-row model"
With wrap on, one document line can occupy several visual rows. Vertical scrolling, the caret and
selection therefore have to work in visual-row space, not document-line space. The heart of this PR is that
mapping:
WrapRowMetrics(pure, WinUI-free) — holds a per-line row count and the cumulative start-row prefixsum, maps document line ↔ visual row (binary search), and supports cheap incremental updates so typing
re-measures only the current line instead of the whole document. The impure per-line measurement (which
needs a
CanvasTextLayout) is injected as a delegate, so all the arithmetic is unit-tested.WrapGeometry(pure) — pointer-Y → visual row, and pointer-Y → within-wrapped-line hit-test Y.Both are covered by
WrapRowMetricsTests/WrapGeometryTests(the incremental-update test asserts itmatches a full rebuild).
Integration
TextLayoutManager— the main text format wraps at the layout width when enabled (line numbers stayno-wrap).
TextRenderer— wrap-metrics lifecycle (EnsureWrapMetrics), visual-rowCalculateLinesToRender,vertical scrollbar sized in visual rows, wrapped
DrawnTextLayoutsizing and draw offset, and thedocument ↔ visual-row helpers.
CursorRenderer— the caret follows its wrapped row (GetCaretPosition().Y) at the line's visual-row top.CursorHelper— a click maps Y → visual row → line, then hit-tests the within-line Y.SelectionRenderer— selection spans wrapped rows automatically (the wrapped layout's ownGetCharacterRegions); only the top margin changes for the scrolled-away rows.MoveCursorByVisualRows), preserving the target column.WordWraponTextControlBox/CoreTextControlBox.Scope & a request for validation
WordWrapis false — every wrap path is gated onIsWordWrapEnabledandreduces to the original values, and the normal render path is byte-identical.
this reviewable — row counting falls back to an estimate above 100k chars so measurement can't blow up, but
rendering a multi-MB wrapped line is a follow-up. Whitespace-glyph visualization in wrap mode is likewise
not offset-adjusted yet.
alignment in wrap mode really wants a run on a real display. The visual-row model is tested and sound; if
the caret/selection sit a hair off in wrap mode, it'll be a small offset constant in
CursorRenderer/SelectionRenderer, not a structural issue. I'd value your eyes here and am happy to iterate.Verification
TextControlBox(library) and the test project build clean (x64).