fix: scroll to the first change using the real text layout in diff view - #2700
Closed
weiningwei wants to merge 1 commit into
Closed
fix: scroll to the first change using the real text layout in diff view#2700weiningwei wants to merge 1 commit into
weiningwei wants to merge 1 commit into
Conversation
love-linger
added a commit
that referenced
this pull request
Sep 13, 2026
… change (#2700) Signed-off-by: leo <longshuang@msn.cn>
Collaborator
|
I've pushed my fix for this BUG which is simpler and faster |
Contributor
Author
|
@love-linger Thanks for the simplification — but unfortunately it doesn't work on some case: maybe the modifyed line is too long? Environment / repro
|
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.

Problem
With "Line Word Wrap" enabled, opening a changed file does not scroll to the first change — the view stays at the top of the diff, above the change.
AutoScrollToFirstChange()estimates the offset aslineHeight * (curBlock.Start - 1), which assumes one visual row per line. Wrapped long lines break that assumption, so the estimate is several times too small: the view either stays at the top of the diff or lands short of the change, instead of centering it.Before / After
src/Resources/Icons.axamlfrom90d9e2ddc2, word wrap enabled:Before — the view stays at the top of the diff, the first change is out of view:
After — the first change is brought into view (block indicator 1/1):
Fix
Offset calculation — ask the real text layout instead of estimating: build the visual lines above the target so their wrapped heights are recorded in the height tree, then use
VisualLine.VisualTop. Lines already built by previous layouts are reused, so only the not-yet-built ones cost anything.Timing — the calculation now depends on the document and the layout, so:
OnDataContextChanged(), before the subclass writes the new text, which means it measured a stale document. It is now scheduled by the subclasses right after the text is written.DispatcherPriority.Background, so it runs after the layout pass, when the document, the scroll extent and the wrapped heights are all up-to-date.Notes
vOffset >= 0guard is kept: no scrolling when the first change is already in the top half of the viewport.ScrollToLine()was avoided — its 0.3 viewport minimum-scroll threshold is meant for caret following and would swallow legitimate jump corrections.