Skip to content

[feature] diff: soft word wrap #153

Merged
jnsahaj merged 11 commits into
jnsahaj:mainfrom
justindotdevv:feat/diff-word-wrap
Jun 3, 2026
Merged

[feature] diff: soft word wrap #153
jnsahaj merged 11 commits into
jnsahaj:mainfrom
justindotdevv:feat/diff-word-wrap

Conversation

@justindotdevv

Copy link
Copy Markdown
Contributor

Summary

Adds soft word wrap to the interactive diff viewer. This was achieved with the assistance of a coding agent: Codex. So if you have time, please do a review (if you still can't or won't I totally understand).

  • Adds lumen diff --wrap to start the diff UI with wrapping enabled
  • Adds w as an in-app toggle for word wrap
  • Wraps long diff lines at word boundaries when possible
  • Preserves indentation on wrapped continuation lines
  • Keeps existing horizontal scrolling behavior when wrap is disabled

Testing

  • cargo check
  • cargo test wrap_tests
  • cargo test test_diff_wrap_parses
  • cargo build

All test pass.

Issues

Closes #149
Closes #119

Demo

screenrecording-2026-05-22_11-20-41.mp4
image

This was referenced May 22, 2026
The merge of main into feat/diff-word-wrap was resolved by naively
accepting both sides of every conflict, which produced code that did
not compile and would have double-rendered every diff row.

app.rs: rewrite the Right/l key handler to mirror Left/h. The previous
resolution left a duplicate nested `if`, an unclosed brace, and a
dead sidebar branch. Also restore main's clamp_h_scroll /
clamp_sidebar_h_scroll calls.

diff_view.rs: fix four render sites that called both push_wrapped_line
and pad_line_bg on the same `spans`, which use-after-moved the vec
and would have pushed each row twice. Each site now branches on
settings.wrap and takes exactly one path. The side-by-side new panel
also now subtracts the correct number of borders (1 when the old
panel is present, 2 otherwise) when computing wrap width.
Add a --wrap flag and in-app w toggle for the diff viewer.

Soft-wrap long diff lines with indentation preserved on continuation rows, keep side-by-side panels aligned, and disable horizontal scrolling while wrapping is active.

Document the feature and cover CLI parsing for the new flag.
- Delete 7 dead_code wrap functions (span_width, spans_width,
  leading_indent_width, flatten_spans, styled_chars_to_spans,
  next_wrap_break, wrap_content_spans) and their associated tests.
  The active wrap implementation lives in wrapped_diff_lines.
- Add missing hook field to DiffOptions test initializers in git.rs
  to fix compilation after upstream merge.
@justindotdevv justindotdevv marked this pull request as ready for review May 31, 2026 13:09
@justindotdevv justindotdevv force-pushed the feat/diff-word-wrap branch from 2aa04a0 to e672f97 Compare June 2, 2026 06:45
Resolved conflicts:
- src/config/cli.rs: removed HookFormat/hook arg, kept wrap arg
- src/main.rs: removed hook field, kept wrap field
- src/command/diff/mod.rs: removed hook field, kept wrap field
- src/command/diff/render/diff_view.rs: accepted overlay-slot rendering from main,
  preserved word-wrap helper functions and wrap rendering
- src/command/diff/git.rs: removed hook field from test DiffOptions structs
@justindotdevv justindotdevv force-pushed the feat/diff-word-wrap branch from e672f97 to 392922f Compare June 2, 2026 07:06
@jnsahaj

jnsahaj commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Hey, love this!

I don't particularly like the ability to toggle word-wrap and also would like to reserve the w to toggle watch mode on/off

we can just allow this via the CLI flag and also an option in lumen.config.json

- Reassign 'w' keybinding from word-wrap toggle to watch mode toggle
- Start/stop file watcher dynamically on watch mode toggle
- Add 'wrap' option to lumen.config.json
- Keep --wrap CLI flag for setting word-wrap at startup
- Return WatchHandle from setup_watcher so dropping it stops the watcher
  thread, preventing leaks on repeated watch toggle cycles
- Guard w key toggle to no-op in PR mode (watch not supported for PRs)
- Set state.watching to false when watcher fails to start
…tch changes

- Set state.watching = false when PR mode is active (prevents fake
  'watching for changes...' indicator in empty-state UI)
- README: change 'w' keybinding from 'Toggle word wrap' to 'Toggle watch mode'
- README: remove duplicate 'w' keybinding entry
- README: update --wrap description to mention lumen.config.json
- README: add 'wrap' option to example config
@jnsahaj jnsahaj merged commit 54cd050 into jnsahaj:main Jun 3, 2026
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.

[Feature request] Add word wrap --wrap flag for diff

2 participants