Skip to content

fix(diffviewer): wrap long lines through delta in side-by-side, mark clipped lines in unified (closes #99)#133

Open
Booyaka101 wants to merge 1 commit into
dlvhdr:mainfrom
Booyaka101:fix/long-line-wrap-99
Open

fix(diffviewer): wrap long lines through delta in side-by-side, mark clipped lines in unified (closes #99)#133
Booyaka101 wants to merge 1 commit into
dlvhdr:mainfrom
Booyaka101:fix/long-line-wrap-99

Conversation

@Booyaka101
Copy link
Copy Markdown
Contributor

@Booyaka101 Booyaka101 commented May 9, 2026

Summary

Closes #99.

diffFile and diffDir invoke delta with --max-line-length=<width>, which is the truncation flag — not a wrap hint. Combined with delta's default --wrap-max-lines=2, any source line longer than roughly two viewport widths got silently dropped in side-by-side mode. In unified mode (where delta does not wrap at all) the long line then hit the post-processing truncation in the diffContentMsg handler, which used an empty tail ("") and clipped without any visible signal.

The reporter pointed at both spots in the original issue — both the delta args and the post-processing pass.

Fix

Two changes, both in pkg/ui/panes/diffviewer/diffviewer.go:

  1. Both diffFile and diffDir — replace --max-line-length=<width> with --max-line-length=0 (disable truncation) and add --wrap-max-lines=unlimited (let delta wrap as many times as needed). Side-by-side mode now wraps long lines all the way through instead of stopping at the second wrap.

  2. diffContentMsg handler — change the ansi.Truncate tail from "" to . Unified mode (where delta does not wrap) at least surfaces a visible cut-off marker instead of vanishing the remainder.

Verification

Local repro with the canonical "very long line" diff at -w=80:

Mode Pre-fix Post-fix
Side-by-side clipped at "what flags delta is invoked with" (≈2 wraps) reaches "to see what happens here" (full content)
Unified line silently cut at viewport width with no marker line cut at viewport width with tail

Verified the args delta receives by running them directly:

$ delta --paging=never -w=80 --max-line-length=0 --wrap-max-lines=unlimited --side-by-side < long.diff
…
│    │                                  │  2 │const Long = "this is a very long↵
│    │                                  │    │ line that should be wrapped or t↵
│    │                                  │    │runcated depending on what flags ↵
│    │                                  │    │delta is invoked with and we want↵
│    │                                  │    │ to see what happens here"
…

Existing pkg/ui/panes/diffviewer test suite passes:

ok  	github.com/dlvhdr/diffnav/pkg/ui/panes/diffviewer	0.361s

The pre-existing TestSearchResultsRenderWhenFileTreeIsHidden, TestBuildFullFileTree, and TestCollapseTree failures on main are unrelated lipgloss-styling drift and are not touched by this PR.

Notes on scope

  • Unified-mode horizontal scrolling is the natural follow-up — delta does not wrap there regardless of the flags above, so the only way to actually read a clipped line right now is s to switch to side-by-side. Happy to send a follow-up that adds horizontal scroll to the viewport if that's wanted, but kept this PR focused on the bug as filed.
  • The --wrap-max-lines=unlimited value is delta's documented sentinel ("a value of unlimited means a line will be wrapped as many times as required").

Credit to @fgrehm for the report and the precise line references in the issue.

…clipped lines in unified (closes dlvhdr#99)

`diffFile` and `diffDir` were invoking delta with `--max-line-length=<width>`,
which is the truncation flag rather than a wrap hint. Combined with delta's
default `--wrap-max-lines=2`, that capped any source line at roughly two
viewport widths in side-by-side mode and silently dropped the rest. In
unified mode, where delta does not wrap, the long line then hit the post-
processing truncation in the `diffContentMsg` handler, which used an empty
tail and clipped without any visible signal.

This commit:

- Replaces `--max-line-length=<width>` with `--max-line-length=0` and adds
  `--wrap-max-lines=unlimited` for both invocations. Side-by-side now wraps
  long lines all the way to the end instead of truncating after two wraps.
  Verified locally: a 162-char line at `-w=80` previously stopped at
  "what flags delta is invoked with"; it now reaches "to see what happens
  here".
- Replaces the empty truncation tail in the `diffContentMsg` handler with
  `…`, so unified-mode lines that exceed the viewport at least signal the
  cut-off rather than vanishing silently.

The existing `diffviewer` test suite still passes. Pre-existing
`TestSearchResultsRenderWhenFileTreeIsHidden`, `TestBuildFullFileTree`, and
`TestCollapseTree` failures on `main` are unrelated to this change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long lines get silently truncated in the diff viewer

1 participant