opentui
opentui copied to clipboard
feat(diff): add word-level highlighting for modified lines
Adds word-level highlighting to show which words changed within modified lines (like GitHub's diff view).
Algorithm:
- Parse diff and group consecutive remove/add lines into change blocks
- Pair lines positionally within each block (1st remove with 1st add, etc.)
- For each pair, compute similarity score using character-level diff
- If similarity >= 40%, compute word boundaries with
diffWordsWithSpace - 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).
New options: showWordHighlights, addedWordBg, removedWordBg, lineSimilarityThreshold