Commit 4d8d3a2
authored
feat(ui): quieter plan diffs on prose edits (#603)
* feat(ui): atomize balanced emphasis pairs in plan diff
Before word-diffing, replace each balanced `**…**`, `__…__`, `~~…~~`,
`*…*`, `_…_` (and triples `***…***` / `___…___`) with a unique
word-char sentinel — same pattern as the existing code-span / link
atomization passes. Identical phrases pair as unchanged; different
phrases produce a single remove+add.
Fixes the "preliminary analysis" → "final analysis" demo case (⑯),
which previously orphaned the closing `**` into the unchanged tail and
rendered as literal asterisks. Now renders as one clean bold-struck →
bold-green swap.
Pair matching uses CommonMark-ish flanking rules so stray `2**3` or
intraword `my__var` / `snake_case` stay literal. Longest-first ordering
prevents single delimiters from eating the inside of a double-delim pair.
* feat(ui): coalesce adjacent diff sites separated by thin tokens
After `diffWordsWithSpace` and sentinel restoration, merge dirty runs
of ≥2 change sites separated only by thin unchanged tokens (whitespace,
commas, periods, semicolons, colons, dashes, quotes) into a single
phrase-level swap. Parens and brackets are excluded so inline links
and bracketed content stay as hard boundaries.
Turns alternating red/green word-noise (e.g. paragraph reworks with
multiple adjacent word swaps) into a readable before/after. Also
rescues the atomization edge case where wrapping a previously-plain
phrase in emphasis (`foo bar baz` → `foo **bar baz**`) would otherwise
surface as fragmented literal delimiters inside colored tags.
Single-site dirty runs pass through unchanged so isolated word swaps
keep word-level highlighting.
* feat(ui): atomize hyphenated compounds in plan diff
Hyphens between word chars (`ninety-five`, `64-byte`, `state-of-the-art`)
are semantic compound words, not two tokens. `diffWordsWithSpace` splits
on word boundaries, so without this pass `ninety-five` → `ninety-nine`
fragments into an unchanged `ninety-` prefix and a swapped `five`/`nine`
suffix — a visually noisy partial-word diff.
Added a sentinel pass that replaces infix hyphens with a word-char
marker before diffing and restores them afterwards. Runs after the
code/link/emphasis passes so hyphens inside those constructs stay
hidden. Unlike the other sentinels this one uses a fixed marker — all
hyphens restore to the same character, so uniqueness isn't needed.
Leading/trailing dashes and em-dash-like separators (dash with space on
one side) are not substituted; only true compound infixes.1 parent b0c5db9 commit 4d8d3a2
4 files changed
Lines changed: 606 additions & 12 deletions
File tree
- apps/hook
- packages
- editor
- ui/utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
486 | | - | |
| 486 | + | |
487 | 487 | | |
488 | | - | |
| 488 | + | |
489 | 489 | | |
490 | 490 | | |
491 | 491 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| |||
0 commit comments