Diff View

Diff view for the code editor: themed changed and deleted lines, chunk navigation with position and line counts, per-chunk and bulk accept or reject actions, keyboard shortcuts, and a side-by-side mode with revert controls between the panes.

UIcode-editor-diffView JSON

The demos are editable: type in the buffer and the diff updates against the fixed original. Accept moves the comparison forward, Reject restores the buffer from it, and Accept all or Reject all settle the remaining chunks. Once nothing is left, Reset comparison brings the demo back. Keyboard: Mod Alt Down and Mod Alt Up move between changes, Mod Enter accepts and Shift Mod Enter rejects the chunk under the cursor. With mode="split" the documents sit side by side instead, and the revert controls between the panes replace the accept and reject actions.

Preview

Ln 1, Col 1tsx
Ln 1, Col 1tsx

Installation

Add the item with the shadcn CLI, or copy the source manually.

pnpm dlx shadcn@latest add litingyes/blocove/code-editor-diff

Requires a shadcn/ui project set up with Base UI primitives. Blocove is developed against the b0 preset, but it installs no base config or theme tokens: your own preset, fonts and colors stay in place.

Or install from the namespace after adding the registry: npx shadcn@latest add @blocove/code-editor-diff

This example also uses: code-editorcode-editor-shikicode-editor-languagescode-editor-line-numbers

pnpm dlx shadcn@latest add litingyes/blocove/code-editor litingyes/blocove/code-editor-shiki litingyes/blocove/code-editor-languages litingyes/blocove/code-editor-line-numbers

API Reference

Props accepted by the exported components.

CodeEditorDiff

Declares the diff view. The editor content is compared against `original`, either inline in one view or side by side with `mode="split"`. Inline, changed lines are themed with the editor tokens and every changed chunk gets accept and reject controls. Split, both documents are aligned chunk by chunk with revert controls between the panes. Changing the props recreates the editor view, so keep the documents stable while chunks are applied.

PropTypeDefault
originalstring-
mode'inline' | 'split''inline'
revertControls'a-to-b' | 'b-to-a' | false'a-to-b'
orientation'a-b' | 'b-a''a-b'
highlightChangesbooleantrue
gutterbooleantrue
mergeControlsbooleantrue
collapseUnchangedfalse | { margin?: number, minSize?: number }{ margin: 2, minSize: 4 }
allowInlineDiffsbooleanfalse
syntaxHighlightDeletionsbooleantrue
shortcutsbooleantrue
labels{ accept?: string, reject?: string }{ accept: 'Accept', reject: 'Reject' }

CodeEditorDiffToolbar

Toolbar controls for the diff view: previous and next change with their position and line counts, accept or reject for the chunk under the cursor, accept or reject for every remaining chunk, and a reset once the review settles. Render it inside the editor toolbar. In split mode the accept and reject actions are hidden automatically, since reverting happens between the panes.

PropTypeDefault
hideCountbooleanfalse
hideActionsbooleanfalse