Repository navigation
Keep gutters aligned with wrapped lines in diff and merge panes - #27
Merged
Merged
Conversation
With 'wrap' on, a long line spans several screen rows but the number panes and connector still advanced one row per buffer line, so numbers, bands and routes drifted out of step with the text (#26). Gutters now work in screen-row space. util/rowmap maps each source pane's buffer lines to screen rows (sparse: only lines taller than one row; the identity without wrap, so unwrapped rendering is unchanged). Number panes put a line's number on its first row and carry its band through continuation rows; base paths are built by running the existing compute_paths over a row-space expansion of the aligned view, so the connector engine is untouched. Gutters scroll to the pane's screen-row topline, including a 'smoothscroll' skipcol, and viewport repaints now restore full window views so that skipcol survives. Resizes and wrap-related option changes rebuild the maps; virtual lines count as rows too. The merge view uses the same maps for its three panes. Fixes #26
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.
Fixes #26.
Problem
With
:set wrapin a diff pane, a line longer than the window takes several screen rows, but the line-number panes and the connector still moved one row per buffer line. Numbers, change bands and routes fell further out of step with each wrapped line (cursor on 376, gutter showing 378).Approach
Gutters now work in screen-row space instead of buffer-line space.
util/rowmap(new): per-pane map from buffer line to screen row. It only stores lines taller than one row, so it stays small, and it is the identity when nothing wraps, which leaves unwrapped rendering exactly as before. Maps are cached per window and rebuilt when the buffer text, the text-area width, or a wrap-related option changes. Each paint re-checks the visible lines so inlay hints and virtual lines are picked up. Virtual lines (e.g. diagnosticvirtual_lines) count as rows even with wrap off.compute_paths, run over a row-space expansion of the aligned view. The connector engine is unchanged. An add/delete origin on a wrapped line attaches to its bottom row.'smoothscroll'skipcol. Viewport repaints now restore full window views (previously topline + cursor only, which dropped the skipcol).WinResized/VimResizedandOptionSetfor wrap-related options rebuild the gutters. Merge also re-renders on resize now.stale_ok), so typing in a large wrapped file doesn't re-measure on every keystroke. Paints re-measure.Cost
Known limits
goto_document_edgeand snap-to-cursor still compute offsets in lines rather than rows. With wrap on they work, but may land a few rows off.Tests
tests/integration/test_wrap.lua: on every visible row, each tagged fixture line's number must sit on the row where the line starts, and continuation rows must be blank. Covered through scrolling either pane,smoothscrollpartway into a wrapped line, toggling wrap off, and resizing. All four cases fail without the fix.tests/specs/33_rowmap.lua: map maths, measuring a real window (long lines, tabs,linebreakrebuild, virtual lines), and row-space path expansion.nvim -l tests/run_all.lua→ 19 jobs, 0 failed.