-
-
Notifications
You must be signed in to change notification settings - Fork 30
Long lines get silently truncated in the diff viewer #99
Description
What's happening
Any diff line longer than the viewport width gets cut off with no way to see the rest. No horizontal scrolling, no wrapping -- the content is just gone.
Weird thing is it happens in two places:
-
deltais called with--max-line-length=<width>, so it clips before output even arrives.
diffnav/pkg/ui/panes/diffviewer/diffviewer.go
Lines 282 to 294 in 2898ff7
useSideBySide := sideBySide && !file.IsNew && !file.IsDelete args := []string{ "--paging=never", fmt.Sprintf("-w=%d", width), fmt.Sprintf("--max-line-length=%d", width), } if useSideBySide { args = append(args, "--side-by-side") } deltac := exec.Command("delta", args...) deltac.Env = os.Environ() deltac.Stdin = strings.NewReader(file.String() + "\n") out, err := deltac.Output() -
Then there's a post-processing pass that truncates anything still wider than the viewport
diffnav/pkg/ui/panes/diffviewer/diffviewer.go
Lines 82 to 95 in 2898ff7
case diffContentMsg: // Truncate lines to viewport width to prevent ANSI escape overflow. lines := strings.Split(msg.text, "\n") for i, line := range lines { if lipgloss.Width(line) > m.vp.Width() && m.vp.Width() > 0 { lines[i] = ansi.Truncate(line, m.vp.Width(), "") } } diff := strings.Join(lines, "\n") if _, ok := m.cache[msg.cacheKey]; ok { m.cache[msg.cacheKey].diff = diff } m.vp.SetContent(diff) }
(The comment there says "to prevent ANSI escape overflow", so I get why it's there but the result is you can't read long lines at all 😬 )
To reproduce
Just use any diff with long lines and / or narrow your terminal a bit and the content just disappears at the right edge.
What I'd expect
Either:
- word wraping: long lines continue on the next visual line (could use
muesli/reflow/wrapwhich is already in go.mod) - or horizontal scrolling: left/right keybinds to pan the viewport
Happy to put up a PR if you have a preference on the approach 🚀