mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 04:55:58 +03:00
[PR #368] feat(diff): add word-level highlighting for modified lines #1267
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#1267
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/anomalyco/opentui/pull/368
Author: @remorses
Created: 11/30/2025
Status: 🔄 Open
Base:
main← Head:word-highlights📝 Commits (10+)
ec432caadd word highlightsc0ceee1test: add word highlight tests85e2afdformat45884fefix: use Bun.stringWidth for multi-width character support in word highlightsebfc48cfix: correct line counts in example diff hunk headera5a9136update react exampled663823rename showWordHighlights to disableWordHighlights117e470chore: remove verbose comments1c2e986refactor: simplify word highlights code6cc3958fix: revert unrelated simplifications to split view forEach loops📊 Changes
7 files changed (+1009 additions, -84 deletions)
View changed files
📝
packages/core/package.json(+1 -0)➕
packages/core/src/benchmark/diff-word-highlights-benchmark.ts(+381 -0)📝
packages/core/src/lib/RGBA.ts(+9 -0)📝
packages/core/src/renderables/Diff.test.ts(+211 -2)📝
packages/core/src/renderables/Diff.ts(+321 -79)📝
packages/core/src/renderables/LineNumberRenderable.ts(+77 -1)📝
packages/react/examples/diff.tsx(+9 -2)📄 Description
Adds word-level highlighting to show which words changed within modified lines (like GitHub's diff view).
Algorithm:
diffWordsWithSpaceComplexity 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:
disableWordHighlights- Turn off word-level highlighting (default:false)addedWordBg- Background color for added words (default: brighteraddedBg)removedWordBg- Background color for removed words (default: brighterremovedBg)lineSimilarityThreshold- Min similarity (0-1) to pair lines for word diff (default:0.4)Also includes:
wrapMode: "none"and horizontal scrolling is used🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.