Repository navigation
feat(file-viewer): syntax-highlight added and removed lines in the diff view - #1594
Merged
agegr merged 4 commits intoNov 12, 2026
Merged
Conversation
Reuse the existing Prism pipeline to color added/removed/context line content in the file diff view. The row background, gutter and +/- marker column stay unchanged; only the code tokens are colored. Plain text files and diffs over SOURCE_HIGHLIGHT_MAX_LINES keep the plain-text fallback.
…ound Each line's highlighter wrapper took the Prism theme's <pre> rules: vs drew a 1px border around every line, both themes' fonts grew each row from 20.8px to 21.8-22.8px, `white-space: pre` (and the code span's own `wrapLongLines`) kept a long line on one row with wrap on, and the `background` shorthand beside vs's backgroundColor left a white box behind each line after a dark-to-light switch, with React's conflicting-property warnings. Reset those on the wrapper and pass the wrap choice through. Memoize the line and the view: with primitive props only, a sidebar toggle no longer runs Prism over every diff line again (931 ms -> 94 ms at 4x CPU throttling on a 651-row diff). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Thanks for picking up #1587! Reusing the source view's highlighter, language detection and line limit is the right shape. Testing it in the browser turned up a few things, which I pushed as commits on top (main merged in, head 2e22427):
tsc, lint and |
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 24, 2026
…ff view (agegr#1594) * feat(file-viewer): syntax-highlight diff view lines Reuse the existing Prism pipeline to color added/removed/context line content in the file diff view. The row background, gutter and +/- marker column stay unchanged; only the code tokens are colored. Plain text files and diffs over SOURCE_HIGHLIGHT_MAX_LINES keep the plain-text fallback. * fix(file-viewer): keep a highlighted diff line's box, wrap and background Each line's highlighter wrapper took the Prism theme's <pre> rules: vs drew a 1px border around every line, both themes' fonts grew each row from 20.8px to 21.8-22.8px, `white-space: pre` (and the code span's own `wrapLongLines`) kept a long line on one row with wrap on, and the `background` shorthand beside vs's backgroundColor left a white box behind each line after a dark-to-light switch, with React's conflicting-property warnings. Reset those on the wrapper and pass the wrap choice through. Memoize the line and the view: with primitive props only, a sidebar toggle no longer runs Prism over every diff line again (931 ms -> 94 ms at 4x CPU throttling on a 651-row diff). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(file-viewer): how the diff view highlights its lines Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: songconmaisaix31-design <songconmaisaix31-design@users.noreply.github.com> Co-authored-by: Alex Yang <agegcn@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1587.
The diff view currently renders every added/removed/context line as plain text, while the source view already colors tokens through Prism. This wires the existing
react-syntax-highlighter/prism-lightpipeline into the diff view so the code content on each row is token-colored, matching the source view.Approach
DiffLineCodehelper that wraps a single line's text in an inline<SyntaxHighlighter>(PreTag/CodeTag =span, transparent background, inherited font/line-height) so the existing row layout — red/green background, line-number gutter,+/-marker column, wrap toggle — is untouched.TextFileVieweralready computeslanguage,prismReadyandisDarkfor the source view; these are passed intoDiffViewas optional props (defaulting to plain text) so the diff view stays self-contained and the existing lightweight render path is unchanged.SOURCE_HIGHLIGHT_MAX_LINESceiling as the source view, so oversized diffs fall back to plain text.<DiffView ... />call site.Testing
node --experimental-strip-types --test components/FileViewer.test.mjs components/FileViewer.state.test.mjs lib/prism-languages.test.mjs→ 6/6 pass.npx eslint components/FileViewer.tsx components/FileViewer.test.mjs→ clean.npx tsc --noEmit→ clean.