Skip to content

feat: side-by-side diff preview, toggled with v - #110

Open
Wahajolla wants to merge 1 commit into
alexarthurs:mainfrom
Wahajolla:side-by-side-diff
Open

Wahajolla wants to merge 1 commit into
alexarthurs:mainfrom
Wahajolla:side-by-side-diff

Conversation

@Wahajolla

Copy link
Copy Markdown

What

Diff previews can be read side by side: v switches between the existing unified view and two columns, old on the left and new on the right. Deleted lines sit on the same row as the additions that replace them, each side keeps its own line numbers, row tint and word-level tint, and long lines wrap within their column (w off clips them instead). The choice is saved as diff_side_by_side and applies to every later diff. Panes narrower than 60 columns fall back to unified, and the footer says v: side by side (too narrow).

Why

Wide panes have room to read a change against what it replaced, the way VS Code's side-by-side diff does, and in a unified view a long run of deletions pushes the additions that replace them off screen.

How it fits in: diffview::render_split reuses the same parse, highlighting and word ranges as render (now shared through one styled pass, so unified output is unchanged and the existing diffview tests pass as before). It needs the pane width, so a diff Doc keeps its raw git diff text and relayout builds the split rows instead of calling build_rows; rows_key includes the layout. Rows are tagged with the unified line they start at, so v keeps the reader's place through pending_src, like w. git show previews stay unified.

Overlap: like #80, #88, #99, #106 and #109, this adds a field to State and its hand-written write_state line, so whichever lands second needs a trivial rebase. No open PR uses v in the preview.

Checklist

  • cargo build --release succeeds (run from plugins/herdr-sidebar)
  • cargo test passes (add/adjust tests for behavior changes) — new side_by_side_pairs_old_and_new_lines, side_by_side_rows_fill_the_width_and_map_to_unified_lines, side_by_side_wraps_within_each_column, side_by_side_keeps_hunk_markers_and_plain_lines_full_width, diff_lays_out_side_by_side_when_toggled_and_wide_enough; state_roundtrip_and_forgiving_parse covers the new field. Locally on macOS, 3 tests fail with and without this change because Apple Git 2.39 predates git checkout --end-of-options (checkout_branch_switches_without_forcing_dirty_work, create_branch_refuses_a_name_already_in_use, drawer_checkout_and_reset_arguments_work_in_a_real_repo); CI's git should be fine.
  • cargo clippy --release -- -D warnings is clean
  • Exercised in a live herdr pane if the change touches the TUI, launcher
    scripts, or persistence (see AGENTS.md "Plugin dev workflow") — macOS, herdr 0.8.2, linked checkout: a working-tree diff of a Go file rendered side by side with paired -/+ rows and a hunk marker, v toggled it and persisted the setting, and the footer showed v: side by side. Not tried on Windows or Linux.
  • README / AGENTS.md updated if keys, persistence, or the manifest changed — README (Source Control bullet, preview keys) and AGENTS.md (Diff preview, settings list)

Draft until it has had some daily use.

🤖 Generated with Claude Code

Diff previews can show old and new in two columns: deletions paired with
the additions that follow them, each side with its own line numbers, row
tint and word-level tint, long lines wrapping within their column. v
toggles it and the choice is saved as diff_side_by_side for every later
diff. Panes narrower than 60 columns fall back to the unified layout.
Toggling keeps the reader's place by source line, like w.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Wahajolla
Wahajolla marked this pull request as ready for review October 16, 2026 18:45
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.

1 participant