Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
57dfac8
feat: parse delta's OSC 1717 line metadata
pablospe Nov 14, 2026
b6f55b3
fix: keep the first row that carries the OSC 1717 handshake
pablospe Nov 14, 2026
45d9dac
feat: keep the scroll position when toggling side-by-side or resizing
pablospe Nov 14, 2026
17254ce
fix: take the scroll anchor before the viewport is resized
pablospe Nov 14, 2026
3c5533e
fix: keep rows without a record in place when restoring the scroll
pablospe Nov 14, 2026
f25396b
refactor: drop the nearest-line fallback and skip rows without records
pablospe Nov 14, 2026
fe2ec61
test: run the real delta without the user's git config
pablospe Nov 14, 2026
0f2c9b6
fix: keep a wrapped-row offset within the anchor line's rows
pablospe Nov 14, 2026
71eb9b4
style: wrap a long test line for golines
pablospe Nov 14, 2026
f0e7568
fix: don't restore the scroll position after the user moved
pablospe Nov 15, 2026
654d4f5
fix: keep the scroll anchor when a scroll call doesn't move
pablospe Nov 15, 2026
67221b4
fix: follow a move made while the re-render is pending
pablospe Nov 15, 2026
6d05cce
docs: say how rows without a record and wrapped rows are anchored
pablospe Nov 15, 2026
18286d9
fix: unquote octal-escaped file names in OSC 1717 records
pablospe Nov 15, 2026
a98623c
fix: don't read records of the previous node while a new one renders
pablospe Nov 25, 2026
f552006
fix: unquote file names that keep git's quotes in OSC 1717 records
pablospe Nov 25, 2026
51b689b
refactor: compute the restored row in a pure anchorRow
pablospe Nov 26, 2026
ed42303
refactor: track view moves in one place
pablospe Nov 26, 2026
e674a5e
refactor: cut OSC 1717 sequences with strings.Cut and unquote names i…
pablospe Nov 26, 2026
74166ba
test: share the line and model fixtures of the scroll tests
pablospe Nov 26, 2026
e2250d9
docs: leave the offset rules to anchorRow's comments
pablospe Nov 26, 2026
771a561
refactor: reanchor after moves without a closure, and jump to edges w…
pablospe Nov 26, 2026
1cf712e
fix: keep g/G pressed at the edge while a re-render is pending
pablospe Nov 26, 2026
1921186
fix: don't overwrite a pending anchor when another re-render starts
pablospe Nov 26, 2026
b95383b
refactor: match records with slices helpers and check the file in sam…
pablospe Nov 26, 2026
45ab706
test: test anchorRow, and sharpen and share the scroll test fixtures
pablospe Nov 26, 2026
e1bda73
test: keep the line scrolled to with the wheel during a pending render
pablospe Nov 26, 2026
0778ecf
test: share the delivery of the pending render in a helper
pablospe Nov 26, 2026
d1f2aba
test: keep G when the wheel doesn't move at the bottom
pablospe Nov 26, 2026
3ca4c08
chore: slight renaming and docs
dlvhdr Nov 30, 2026
c0da15c
feat: report the file and line under the diff view
pablospe Nov 14, 2026
5ce01c0
feat: open $EDITOR at the line under the diff view
pablospe Nov 14, 2026
e3d60f3
docs: document ui.editorLineArg and opening at the line
pablospe Nov 14, 2026
0e02d0e
docs: show the default editorLineArg in the example config
pablospe Nov 15, 2026
a16b759
style: wrap long test lines for golines
pablospe Nov 15, 2026
a333387
fix: open the line on screen while a re-render is pending
pablospe Nov 15, 2026
3e70bf5
fix: run $EDITOR through sh like git does
pablospe Nov 15, 2026
4de8901
docs: say o falls back to the tree node and runs $EDITOR through sh
pablospe Nov 15, 2026
9d0b76c
fix: open the added line of a side-by-side row
pablospe Nov 25, 2026
4216023
fix: pass an absolute path to the editor outside a repo
pablospe Nov 25, 2026
1a56220
fix: keep $EDITOR as one program path on Windows
pablospe Nov 25, 2026
fdc91f2
docs: say what o opens on file headers and side-by-side rows
pablospe Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ ui:
# Render diffs with your own delta config instead of the theme colors. The
# rest of the UI keeps the theme above. (default: false)
useUserDeltaTheme: true

# Arguments for $EDITOR when `o` knows the line (needs delta >= 0.20).
# {file} and {line} are replaced; without a line it runs `$EDITOR <file>`.
# The default works for vim, nvim, nano, emacs, ... For other editors:
# VS Code: "-g {file}:{line}", helix/zed/subl: "{file}:{line}"
editorLineArg: "+{line} {file}"
```

| Option | Type | Default | Description |
Expand All @@ -204,6 +210,7 @@ ui:
| `ui.startFoldersOpenDepth` | int | `-1` | Folder open depth on start (-1 = all, 0 = none) |
| `ui.theme` | string | `tokyo_night` | The ID of the theme to use |
| `ui.useUserDeltaTheme` | bool | `false` | Render diffs with your own delta config |
| `ui.editorLineArg` | string | `+{line} {file}` | `$EDITOR` args to open at a line (`{file}`, `{line}`) |

### Icon Styles

Expand Down Expand Up @@ -232,12 +239,14 @@ ui:
| <kbd>t</kbd> | Search/go-to file |
| <kbd>y</kbd> | Copy file path |
| <kbd>i</kbd> | Cycle icon style |
| <kbd>o</kbd> | Open file in $EDITOR |
| <kbd>o</kbd> | Open file at line in $EDITOR |
| <kbd>s</kbd> | Toggle side-by-side/unified view |
| <kbd>Tab</kbd> | Switch focus between the panes |
| <kbd>T</kbd> | Open the theme picker |
| <kbd>q</kbd> | Quit |

<kbd>o</kbd> opens the file at the line at the top of the diff, or at the selected line when selection is on. Deleted lines open at their place in the new file, hunk headers at the hunk start, and a side-by-side row at the line on its right side. In the directory view it opens the file under that line. A file header opens just that file. Without any line information (delta older than 0.20) it opens the selected tree node, as before. Like git, it runs `$EDITOR` through `sh`, so it can carry arguments (`code -w`) or a quoted path; on Windows `$EDITOR` is the editor's path. See `ui.editorLineArg` for editors that don't take `+N`.

## Discord

Have questions? Join our [Discord community](https://discord.gg/SXNXp9NctV)!
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type UIConfig struct {
StartFoldersOpenDepth int `yaml:"startFoldersOpenDepth"` // How many levels of folders to open on start (-1 = all, 0 = none)
Theme string `yaml:"theme"` // The theme to use (default: "tokyo_night")
UseUserDeltaTheme bool `yaml:"useUserDeltaTheme"` // Use the user's delta config for diffs (default: false)
EditorLineArg string `yaml:"editorLineArg"` // $EDITOR arguments when the line is known, with {line} and {file} (default: "+{line} {file}")
}

type WatchConfig struct {
Expand Down Expand Up @@ -50,6 +51,7 @@ func DefaultConfig() Config {
ShowDiffStats: true,
StartFoldersOpenDepth: -1,
Theme: tint.TintTokyoNight.ID,
EditorLineArg: "+{line} {file}",
},
}
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/ui/panes/diffviewer/delta_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ func TestMakeDeltaArgs(t *testing.T) {
func TestMakeDeltaEnv(t *testing.T) {
t.Setenv("GIT_CONFIG_PARAMETERS", "'delta.navigate'='true'")

if got := makeDeltaEnv(deltaOpts{SideBySide: true}); !slices.Equal(got, os.Environ()) {
t.Fatalf("themed: expected the plain environment, got %q", got)
wantEnv := append(os.Environ(), "OSC1717=V1")
if got := makeDeltaEnv(deltaOpts{SideBySide: true}); !slices.Equal(got, wantEnv) {
t.Fatalf("themed: expected %q, got %q", wantEnv, got)
}

env := makeDeltaEnv(deltaOpts{UseUserDeltaTheme: true})
if !slices.Contains(env, "OSC1717=V1") {
t.Errorf("user delta theme: expected OSC1717=V1 in %q", env)
}
got := env[len(env)-1]
want := "GIT_CONFIG_PARAMETERS='delta.navigate'='true' 'delta.side-by-side'='false'"
if got != want {
Expand Down
185 changes: 172 additions & 13 deletions pkg/ui/panes/diffviewer/diffviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func cacheKey(path string, sideBySide bool) string {
}

type diffLine struct {
item item.Item
item item.Item
records []oscRecord
}

func (o diffLine) GetItem() item.Item {
Expand Down Expand Up @@ -95,8 +96,31 @@ type Model struct {
useUserDeltaTheme bool
preamble string
sb common.Scrollbar
// shown are the lines on screen: the last render while a new one is pending.
shown []diffLine
// anchor is where to scroll back to once the re-rendered diff is shown.
anchor *scrollAnchor
}

// scrollAnchor is where to scroll back to after a re-render
type scrollAnchor struct {
// whether the user explicitly navigated to the top or bottom
edge anchorEdge

// otherwise - the position the view was in: the line's osc record and the view's offset from its first row.
oscRec oscRecord
offset int
}

// anchorEdge is the edge of the diff an anchor sticks to, if any.
type anchorEdge int

const (
edgeNone anchorEdge = iota
edgeTop
edgeBottom
)

// SetPreamble stores the preamble text (e.g. commit metadata from git show).
func (m *Model) SetPreamble(preamble string) {
m.preamble = preamble
Expand Down Expand Up @@ -228,13 +252,23 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
}
node.diff = msg.lines
if node == m.file || node == m.dir {
m.fvp.SetObjects(msg.lines)
m.setLines(msg.lines)
}
}

edge := edgeNone
if k, ok := msg.(tea.KeyPressMsg); ok && !m.fvp.FilterFocused() {
if key.Matches(k, ViewportKeyMap.Top) {
edge = edgeTop
} else if key.Matches(k, ViewportKeyMap.Bottom) {
edge = edgeBottom
}
}
row := m.currentRow()
fvp, fvpCmd := m.fvp.Update(msg)
cmds = append(cmds, fvpCmd)
m.fvp = fvp
m.reanchor(row, edge)

return m, tea.Batch(cmds...)
}
Expand All @@ -257,6 +291,8 @@ func (m Model) View() string {
}

func (m *Model) SetSize(width, height int) tea.Cmd {
// Before resizing: the viewport clamps its top row to the new size.
m.saveAnchor()
m.Width = width
m.Height = height
m.fvp.SetWidth(m.contentWidth())
Expand All @@ -266,10 +302,124 @@ func (m *Model) SetSize(width, height int) tea.Cmd {
}

func (m *Model) UpdateTheme() tea.Cmd {
m.saveAnchor()
m.ClearCache()
return m.diff()
}

// saveAnchor remembers the diff osc record at the top of the view (or the selected one) and
// the view's offset from its first row, so the next render scrolls back to it (anchorRow).
func (m *Model) saveAnchor() {
// there's already a valid anchor
if m.anchor != nil {
return
}
if rec, ok := m.currentOSCRecord(); ok {
m.anchor = &scrollAnchor{oscRec: rec, offset: m.currentRow() - findOSCRecord(m.shown, rec)}
}
}

// currentOSCRecord returns the first record at or below the current row of the lines on
// screen, so it is correct even while a new render is pending.
func (m *Model) currentOSCRecord() (oscRecord, bool) {
row := m.currentRow()
if row < 0 || m.fvp.GetMatchingItemsOnly() {
return oscRecord{}, false
}
return firstOSCRecord(m.shown, row)
}

// currentRow is the selected row, or the top visible one without a selection.
func (m *Model) currentRow() int {
if m.SelectionEnabled() {
return m.fvp.GetSelectedItemIdx()
}
return m.fvp.GetItemMetrics().FirstVisibleItemIdx
}

// reanchor keeps a pending render from undoing a move the user made from row: a jump to
// the top or bottom (edge) stays there, other moves keep the line they land on.
func (m *Model) reanchor(row int, edge anchorEdge) {
if m.anchor == nil {
return
}
if edge != edgeNone {
m.anchor = &scrollAnchor{edge: edge}
return
}
if m.currentRow() == row {
return
}
m.anchor = nil
m.saveAnchor()
}

// EditorTarget returns the file (relative to the repo root) and line shown by the
// selected or top visible row, from its OSC 1717 record. line is 0 when the row has
// no line (a file header); ok is false when there is no record.
func (m *Model) EditorTarget() (file string, line int, ok bool) {
rec, ok := m.currentOSCRecord()
if !ok {
return "", 0, false
}
if row := findOSCRecord(m.shown, rec); row >= 0 {
rec = newSide(m.shown[row].records)
}
return rec.File, editorLine(rec), true
}

// setLines shows lines and scrolls to the pending anchor, if any.
func (m *Model) setLines(lines []diffLine) {
m.shown = lines
m.fvp.SetObjects(lines)
if m.anchor == nil {
return
}
a := *m.anchor
m.anchor = nil
switch a.edge {
case edgeTop:
m.fvp.GoToTop()
return
case edgeBottom:
m.fvp.GoToBottom()
return
}
if m.fvp.GetMatchingItemsOnly() {
return
}
row, ok := anchorRow(lines, a.oscRec, a.offset)
if !ok {
return
}
if m.SelectionEnabled() {
m.fvp.SetSelectedItemIdx(row)
return
}
m.fvp.GoToTop()
m.fvp.ScrollDown(row)
}

// anchorRow returns the row offset rows from rec's first row, or false when rec is gone.
// Rows above it (offset < 0) have no record, like blank or decoration rows. Rows below it
// are its wrapped rows, so it stops at the line's last row.
func anchorRow(lines []diffLine, rec oscRecord, offset int) (int, bool) {
row := findOSCRecord(lines, rec)
if row < 0 {
return 0, false
}
if offset < 0 {
return max(row+offset, 0), true
}
for range offset {
if row+1 == len(lines) || !lines[row+1].showsOSCRecord(rec) {
break
}
row++
}
return row, true
}

func (m Model) contentWidth() int {
return m.Width - scrollbarWidth
}
Expand All @@ -281,7 +431,7 @@ func (m *Model) diff() tea.Cmd {
key := cacheKey(m.file.path, sideBySide)
if cached, ok := m.cache[key]; ok && len(cached.diff) != 0 {
m.file = cached
m.fvp.SetObjects(cached.diff)
m.setLines(cached.diff)
return nil
}
node := &cachedNode{
Expand All @@ -297,7 +447,7 @@ func (m *Model) diff() tea.Cmd {
key := cacheKey(m.dir.path, m.sideBySide)
if cached, ok := m.cache[key]; ok && len(cached.diff) != 0 {
m.dir = cached
m.fvp.SetObjects(cached.diff)
m.setLines(cached.diff)
return nil
}
node := &cachedNode{
Expand Down Expand Up @@ -363,14 +513,16 @@ func (m Model) dirHeaderView() string {

func (m Model) SetFilePatch(file *gitdiff.File) (Model, tea.Cmd) {
m.dir = nil
// The rows on screen are another node's until this one is shown.
m.anchor, m.shown = nil, nil

fname := filenode.GetFileName(file)
sideBySide := m.sideBySide && !file.IsNew && !file.IsDelete
key := cacheKey(fname, sideBySide)
if cached, ok := m.cache[key]; ok {
m.file = cached
m.updateHeader()
m.fvp.SetObjects(cached.diff)
m.setLines(cached.diff)
return m, nil
}

Expand All @@ -391,12 +543,13 @@ func (m Model) SetFilePatch(file *gitdiff.File) (Model, tea.Cmd) {

func (m Model) SetDirPatch(dirPath string, files []*gitdiff.File) (Model, tea.Cmd) {
m.file = nil
m.anchor, m.shown = nil, nil

key := cacheKey(dirPath, m.sideBySide)
if cached, ok := m.cache[key]; ok {
m.dir = cached
m.updateHeader()
m.fvp.SetObjects(cached.diff)
m.setLines(cached.diff)
return m, nil
}

Expand Down Expand Up @@ -428,17 +581,22 @@ func (m *Model) updateHeader() {
// SetSideBySide updates the diff view mode and re-renders.
func (m *Model) SetSideBySide(sideBySide bool) tea.Cmd {
m.sideBySide = sideBySide
m.saveAnchor()
return m.diff()
}

// ScrollUp scrolls the viewport up by the given number of lines.
func (m *Model) ScrollUp(lines int) {
row := m.currentRow()
m.fvp.ScrollUp(lines)
m.reanchor(row, edgeNone)
}

// ScrollDown scrolls the viewport down by the given number of lines.
func (m *Model) ScrollDown(lines int) {
row := m.currentRow()
m.fvp.ScrollDown(lines)
m.reanchor(row, edgeNone)
}

// ScrollBottom scrolls the viewport to the bottom.
Expand Down Expand Up @@ -488,7 +646,7 @@ func (m *Model) diffFile(node *cachedNode, width int) tea.Cmd {
return common.ErrMsg{Err: err}
}

return diffContentMsg{cacheKey: key, node: node, lines: stringToDiffLines(string(out))}
return diffContentMsg{cacheKey: key, node: node, lines: parseDeltaOutput(string(out))}
}
}

Expand Down Expand Up @@ -522,11 +680,11 @@ func (m *Model) diffDir(dir *cachedNode, width int, sideBySide bool, preamble st
return common.ErrMsg{Err: err}
}

text := string(out)
lines := parseDeltaOutput(string(out))
if preamble != "" {
text = m.renderPreamble(preamble) + "\n" + text
lines = append(stringToDiffLines(m.renderPreamble(preamble)), lines...)
}
return diffContentMsg{cacheKey: key, node: dir, lines: stringToDiffLines(text)}
return diffContentMsg{cacheKey: key, node: dir, lines: lines}
}
}

Expand Down Expand Up @@ -623,10 +781,11 @@ type deltaOpts struct {
UseUserDeltaTheme bool
}

// makeDeltaEnv sets side-by-side like `git -c delta.side-by-side=...` would.
// The --side-by-side flag would override the user's line-number format and can't turn it off.
// makeDeltaEnv asks for OSC 1717 line metadata and, with the user's theme, sets side-by-side
// like `git -c delta.side-by-side=...` would. The --side-by-side flag would override the
// user's line-number format and can't turn it off.
func makeDeltaEnv(opts deltaOpts) []string {
env := os.Environ()
env := append(os.Environ(), "OSC1717=V1")
if !opts.UseUserDeltaTheme {
return env
}
Expand Down
Loading
Loading