Repository navigation
Conversation
Set OSC1717=V1 for delta and, when its output starts with the handshake, attach each row's line records to the diff line and strip them from the text. Older delta ignores the variable and renders as before.
Delta writes the handshake in front of its first row, not on a row of its own.
Remember the diff line at the top of the view (or the selected one) and, once the re-rendered diff is shown, scroll back to the row with the same OSC 1717 record. Keeping the row index drifted, since unified and side-by-side lay out a different number of rows. Without records the index is kept as before.
Resizing first let the viewport clamp its top row to the old row count, so a taller pane near the bottom moved up. Also skip the anchor when no content row is visible.
Remember the top row's offset from the first row of its anchor record, so a preamble, delta's decoration rows and wrapped rows stay where they were instead of snapping to the record.
Re-renders show the same patch, so the exact record is always there.
When the new layout wraps the anchor line over fewer rows, the offset spilled onto the next diff line. Rows above the anchor keep their offset.
A scroll or jump made before the re-render arrives is no longer undone by the anchor taken at the s press or resize.
ScrollUp/Down/Top/Bottom dropped the pending anchor even at the edge of the diff, where they don't move. They now share Update's check.
Scrolling right after s or a resize kept the row index on the new layout, so a relative move landed on another line. The viewer now keeps the lines on screen and re-anchors to the line the move lands on; g and G still go to the top and bottom. currentRecord gives the record of the current row from those lines.
Git quotes non-ASCII names with octal escapes and delta copies them into the record, so a.txt with an umlaut came through as \303\244.txt.
Near the end of the diff the view stops short of a hunk, so the next ] aimed at the same hunk again and [ skipped back past it. The next jump now counts from the hunk while the view still shows the same top row.
A hunk start is the first row of its record, so the offset was 0, or wrong when the same line appears earlier in the diff.
Delta prints records that hand-built rows don't: deleted lines with a fixed new line under -U0, and deleted and added lines on one side-by-side row.
This comment has been minimized.
This comment has been minimized.
This was referenced Nov 25, 2026
pablospe
marked this pull request as draft
November 26, 2026 12:37
Contributor
Author
|
Marked as draft because it depends on #168. |
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.
Summary
Part 3 of the OSC 1717 series started in #168. Stacked on #168 (OSC 1717 line metadata): it uses the records that PR parses, so it should be reviewed and merged after it. Until then the diff here includes #168's commits; the last thirteen are this PR. Only this PR's changes: pablospe/diffnav@osc1717...hunk-nav
Closes #176.
]scrolls the next hunk to the top of the diff,[the previous one (or the start of the current hunk when you are inside it, like vim's[[). In selection mode they move the selection instead. At the last / first hunk they stay put. They work in a directory view across files, and are ignored while searching or filtering, liken/p.hrecord, including the decoration rows around it (a boxed or over/underlined header is three rows with the sameh), so a hunk starts at the first row of a run of the sameh. But delta prints no header at all for a hunk without a code fragment (nothing after@@) when the hunk-header style shows no line number or file. diffnav's own style is like that, so in themed mode many hunks have nohrecord. Fixed in delta main (Emit the h record when the hunk header row is skipped dandavison/delta#2334: thehrecord goes on the blank row above the hunk), so the fallback is only for 0.20.x releases. Checked with a delta built from main: every hunk then starts on anhrow and the fallback adds nothing. For those, a hunk starts at the firstc/a/drow after a file header, where the new line number jumps by more than one, or where a deleted line skips an old line (adjacent-U0hunks). Wrapped rows count once. Still missed: an addition-only hunk right before a deletion hunk with-U0and no header, since added lines carry no old line.sor a resize: the keys work on the lines on screen, so a jump made before the re-render arrives lands on that hunk in the new render instead of being undone (like feat: keep the scroll position when toggling side-by-side or resizing #168 does for scrolling).Known limit: near the end of a diff the viewport can't scroll the last hunks to the top, so
]shows no change there. The next]or[still counts from the hunk it went to, so[steps back through those hunks instead of skipping them.Possible follow-ups:
]at the last hunk of a file could move on to the next file, and in a directory view the file tree selection doesn't follow yet when]/[crosses into another file.How Did You Test this Change?
-U0,-U1,-U3, unified and side-by-side, 80 and 200 columns) and checks that every hunk is found, also with everyhrecord removed.go test ./...,go vet ./...and golangci-lint v2.12.2 pass.-U0), withhunk-header-styleset to diffnav's color-only style,omit,line-numberandfile line-number syntax, unified and side-by-side, at 50 and 200 columns: every@@is found exactly once, also with everyhrecord removed, and also for two-U0deletions one line apart.ui.useUserDeltaTheme(a boxedfile line-numberheader), unified and side-by-side, and in selection mode. With delta 0.18.2 the keys do nothing.Images/Videos
Delta built from main, diffnav's own theme, a directory view with three files:
main.go(a headerless hunk at the top of the file, then two hunks with afuncheader) andscores.csv(three headerless hunks, which land on delta's blank row carrying thehrecord), withweights.csvbelow so those hunks can reach the top. In side-by-side:]six times through all of them,[twice; thensto switch to unified (the position is kept),]twice and[once.AI disclosure
Claude Code was used to write the code and tests. I reviewed the changes and tested them manually.