Diff Viewer Widget
The diff viewer widget displays file diffs in unified or side-by-side mode with syntax highlighting, hunk navigation, and intra-line change highlighting.Basic Usage
View Modes
Unified Mode
Traditional diff format with added/deleted lines interleaved:Side-by-Side Mode
Two-column layout showing old and new versions:Parsing Unified Diff
Parse standard unified diff output:Intra-Line Highlighting
Highlight specific character ranges that changed within a line:Hunk Navigation
Hunk Actions
Stage/Unstage Hunks
Apply/Revert Hunks
Expand/Collapse Hunks
File Status
Thestatus field indicates the type of change:
Context Lines
Control how many context lines to show around changes:Line Numbers
Git Workflow Example
Diff Colors
Default color scheme (customizable via theme):Flatten Hunks for Rendering
Props Reference
DiffViewerProps
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | Required | Widget identifier |
diff | DiffData | Required | Diff data to display |
mode | "unified" | "sideBySide" | Required | View mode |
scrollTop | number | Required | Vertical scroll position |
onScroll | (scrollTop: number) => void | Required | Scroll callback |
expandedHunks | readonly number[] | — | Expanded hunk indices |
focusedHunk | number | — | Currently focused hunk |
lineNumbers | boolean | true | Show line numbers |
contextLines | number | 3 | Context lines around changes |
focusedHunkStyle | TextStyle | — | Focused hunk header style |
onHunkToggle | (hunkIndex: number, expanded: boolean) => void | — | Hunk expand callback |
onStageHunk | (hunkIndex: number) => void | — | Stage hunk callback |
onUnstageHunk | (hunkIndex: number) => void | — | Unstage hunk callback |
onApplyHunk | (hunkIndex: number) => void | — | Apply hunk callback |
onRevertHunk | (hunkIndex: number) => void | — | Revert hunk callback |
focusable | boolean | true | Include in tab order |
accessibleLabel | string | — | Accessibility label |
focusConfig | FocusConfig | — | Focus appearance |
scrollbarVariant | "minimal" | "classic" | "modern" | "dots" | "thin" | "minimal" | Scrollbar style |
scrollbarStyle | TextStyle | — | Scrollbar color |
DiffData
| Field | Type | Description |
|---|---|---|
oldPath | string | Original file path |
newPath | string | New file path |
hunks | readonly DiffHunk[] | Diff hunks |
isBinary | boolean | Binary file flag |
status | "added" | "deleted" | "modified" | "renamed" | "copied" | File change status |
DiffHunk
| Field | Type | Description |
|---|---|---|
oldStart | number | Original line range start |
oldCount | number | Original line count |
newStart | number | New line range start |
newCount | number | New line count |
header | string | Optional header text |
lines | readonly DiffLine[] | Hunk lines |
DiffLine
| Field | Type | Description |
|---|---|---|
type | "context" | "add" | "delete" | Line type |
content | string | Line content |
oldLineNumber | number | Original line number |
newLineNumber | number | New line number |
highlights | readonly [number, number][] | Intra-line change ranges |
Related Widgets
- Code Editor - Multi-line code editing
- Logs Console - Streaming output display
Location in Source
- Implementation:
packages/core/src/widgets/diffViewer.ts - Types:
packages/core/src/widgets/types.ts:2014-2103 - Factory:
packages/core/src/widgets/ui.ts:diffViewer()