opentui icon indicating copy to clipboard operation
opentui copied to clipboard

feat(diff): add word-level highlighting for modified lines

Open remorses opened this issue 1 week ago • 1 comments

Adds word-level highlighting to show which words changed within modified lines (like GitHub's diff view).

Algorithm:

  1. Parse diff and group consecutive remove/add lines into change blocks
  2. Pair lines positionally within each block (1st remove with 1st add, etc.)
  3. For each pair, compute similarity score using character-level diff
  4. If similarity >= 40%, compute word boundaries with diffWordsWithSpace
  5. Pass highlight column ranges to LineNumberRenderable for rendering

Complexity is O(L + B×P×C²) where L=lines, B=change blocks, P=pairs per block, C=chars per line. In practice C is small (~100) and only change blocks are processed.

Performance guards: skips word diff for dissimilar lines, skips entirely for large blocks (>50 lines).

Screenshot 2025-11-30 at 18 01 50

New options: showWordHighlights, addedWordBg, removedWordBg, lineSimilarityThreshold

remorses avatar Nov 30 '25 16:11 remorses