Skip to content

feat: let a host set the tab width, the inline change mode and whitespace hiding - #19

Merged
backnotprop merged 7 commits into
mainfrom
feat/more-options
Nov 24, 2026
Merged

backnotprop merged 7 commits into
mainfrom
feat/more-options

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

Adds three display settings that a host can change while a review is open. Each one has a setter and a getter on Engine, can be set before the first file arrives, and stays set across replace(). The public API only grows. InlineChanges and Whitespace are #[non_exhaustive], and TabWidth keeps its value private.

Setting Values Default
set_tab_width(TabWidth::new(n)) 1..=16 cells TabWidth::DEFAULT (4)
set_inline_changes(mode) Word, WordAlt, Char, None (the names of Pierre's lineDiffType) Word
set_whitespace(mode) Show, IgnoreChange (git diff -b), IgnoreAll (git diff -w, GitHub's "Hide whitespace") Show

Default behaviour

The first commit records digests of every frame the engine draws at its defaults: 5 patches, split, unified and auto layouts, wrap on and off, 4 sizes, and a sequence of moves. It was recorded on main, before any change. The second commit keeps it passing without re-recording, so every default frame is byte-identical.

Tab width

The geometry cache measures tabs at the set width, and changing it clears the cache. Wrapping, horizontal scroll, clicks, row_at, word emphasis and search highlights all go through the cache, on both split sides. The cursor's line keeps its screen row, as when wrap is toggled.

Inline changes

  • The mode goes to the highlight worker with the request. Request does not change.
  • Changing the mode re-colors the visible lines, as a theme change does.
  • WordAlt joins two word changes when exactly one unchanged grapheme separates them.
  • Char compares graphemes. If either line has more than 1,000 characters, it compares by word.
  • None emphasizes nothing.

Whitespace

  • In each block of removed and added lines, the engine pairs lines that are equal after -b/-w normalization. It uses the longest common subsequence, keeping the order of both sides. Blocks larger than 4,096 lines pair only their matching start and end.
  • A pair is drawn as context, with both numbers and no sign or emphasis. Unified shows the new text.
  • A hunk whose every change is a pair shows only its heading, marked · whitespace only.
  • The review shows a document of re-projected files that share the original spools. Search, sources, gaps the person revealed, selection and the worker all read that document.

Limits, also in the Whitespace rustdoc and docs/embedding.md:

  • Unpaired lines stay changes, blank lines included.
  • Lines are paired only within one block.
  • Hunks keep the patch's boundaries and context.
  • Files and their counts are unchanged, and a file with only whitespace changes keeps its heading.
  • Lines of a hidden hunk cannot be revealed, selected or found by search.
  • Search finds a pair by its new text only.

Tests

  • src/engine/tests/settings.rs (16 tests): unified and split, wrap on and off, ratios 500 and 300, row_at/cursor_row on every row after each change, an open selection, the cursor on a hidden line, a paired line and a row with no line, bursts of mixed changes, panes down to 30x5, files arriving while whitespace is hidden, and revealed context of checked sources.
  • Unit tests in src/whitespace.rs (-b/-w semantics, pairing) and src/highlight/inline.rs (each mode).
  • tests/default_frames.rs for the defaults.

Performance

Synthetic 3,000-file patches, release build, M-series Mac:

  • 192k lines (formatter-style reindents plus real edits): hiding takes 18-23 ms, showing again 0.5 ms.
  • 600k lines, all reindented: hiding takes 64-68 ms.
  • Frames and paging while hidden cost the same as with every change shown.
  • The default path is unchanged. Load medians over 15 runs are 78.2 ms before and 79.0 ms after, which is within noise. Frame, page and search times are equal.

A corpus of patches, including a new one with tabs, whitespace-only
changes, CRLF, wide characters and an interleaved hunk, opened in each
layout, with and without wrapping, at four sizes, paged, scrolled and
toggled. The digests come from this commit, before any new option, so
later changes that alter a default frame fail with the frame printed.
…pace hiding

Three display settings for hosts, each with a setter and a getter on Engine,
settable before the first file arrives and kept across replace():

- set_tab_width(TabWidth): tabs 1 to 16 cells wide, default 4, everywhere
  code is measured or drawn, on both split sides.
- set_inline_changes(InlineChanges): Word (default), WordAlt, Char and None,
  named after Pierre's lineDiffType.
- set_whitespace(Whitespace): Show (default), IgnoreChange (git diff -b) and
  IgnoreAll (git diff -w). Removed and added lines of one block that match
  apart from whitespace are drawn as unchanged; a hunk with no other change
  shows only its heading. The cursor keeps its line, or goes to the row
  that shows it now.

At their defaults every frame is the same as before, as the recorded
default-frames test checks.
…back failed settings

- Vertical tab and form feed are not whitespace to git diff -b or -w, so a
  change to or from them stays a change.
- A pair drawn as unchanged reports both line numbers from selected_source
  in the split layout too, and from a search match's location.
- set_tab_width and set_whitespace build everything that can fail first and
  put the review back if reflowing fails, so the getters always describe
  what is drawn.
- The changelog entries move under a new Unreleased heading above 0.2.3.
App::reveal_source and App::reveal decided whether the cursor's line was on
screen from the rows of the last frame, a list reveal_source clears. A
second reveal before the next draw, such as a host revealing the first line
of a range it just selected, found the list empty and scrolled the line to
the bottom of the pane. Both now lay the rows out from the top, as the
frame does, so any number of reveals, selections and search jumps between
frames leave a line on screen where it is. The screen row a reflow keeps
falls back to the same layout when the list is empty.
…what is hidden

Unified, a pair drawn as unchanged shows only its added line, but its row
took the height of the taller of its two lines, so an old line that wrapped
further left empty rows under it. One function, render::drawn_lines, now
gives the lines a row draws, and the row's height, its scroll limit and the
line the cursor's position is kept by all go by it.

Engine::hunk_is_whitespace_only and DiffRow::whitespace_only give the
engine's own verdict on what the whitespace setting hides.
@backnotprop
backnotprop merged commit 8bc1238 into main Nov 24, 2026
3 checks passed
sebastianst pushed a commit to sebastianst/plannotator-tui that referenced this pull request Nov 24, 2026
…tings (plannotator#197)

* feat(review): whitespace, tab width and changed-text settings

W (toggle-whitespace) hides changes that only touch whitespace, like
git diff -w, and shows them again; a lit 'no ws' chip in the header says
when they are hidden. The settings menu gains Whitespace, Tab width and
Changed text rows, applied live, remembered with the other choices and
settable in [review] (whitespace, tab_width, inline_changes).

A selection whose hunk becomes a heading alone is cleared and said so;
go to definition opens such a line in the whole file. Bursts of W are
taken as one change at the next frame.

Also: a remembered-settings file that cannot be read is replaced by the
next write or Reset; a config that fails to load is said once in the
footer of the review and document screens; going to the only file's
heading no longer loops for ever.

Uses diffs-rs feat/more-options (plannotator/diffs-rs#19) through
[patch.crates-io] until it is published.

* fix(review): follow diffs-rs c70c80f, where a form feed or vertical tab is not whitespace

The patched diffs crates move to the branch head, which carries 0.2.3.
The app's rule for a hunk the viewer hides takes only space, tab, CR and
LF as whitespace, as the viewer and git diff -w/-b do, so a change to a
form feed stays shown and selectable.

* test(review): a drag up with whitespace hidden keeps the view; follow diffs-rs e320ae7

The patched diffs crates move to e320ae7, where a reveal of a line already
on screen never scrolls. A Screen test drags up in a scrolled diff with
whitespace hidden, tab width 2 and 8, changed text off, split and unified:
the view stays, the lines are those dragged over, pairs drawn as unchanged
included, and the comment saves their file, side and lines.

The wrapped-line comment-box test relied on the reveal that scrolled; it
now brings line 30 up with the wheel so the wrapped lines fit under it.

* fix(review): ask the viewer which hunks hide as whitespace; W over the file list too

The patched diffs crates move to b7ef59d, which says itself whether a hunk
is drawn as its heading alone (Engine::hunk_is_whitespace_only). The app's
copy of that rule is gone: it read the patch as UTF-8, so a Latin-1 line
changed from caf\xe9 to caf\xe8 compared equal, and W cleared a selection
on a line still drawn. The app now only finds a line's hunk from the
viewer's hunk headings and asks.

W hides and shows whitespace over the file list and the notes too, unless
the pane gives the key to one of its own; the footer said so already.

* build: use published diffs-rs 0.2.4
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