Diff viewer
Review an agent's change set: unified, split or stacked, Accept / Reject (or Keep / Undo) per hunk, per file and for all with undo, a file list with Viewed marks, hidden context on demand, line comments sent to the agent together, and a minimap.
oxyn add diff-viewer@@ -1,9 +1,11 @@+4 −2@@ -15,5 +17,6 @@fn check+1@@ -1,11 +1,18 @@struct Session+8 −1@@ -0,0 +1,14 @@+14@@ -1,2 +0,0 @@−2let files = vec![
FileDiff::new("src/auth.rs", old_auth, new_auth),
FileDiff::new("src/rate.rs", "", new_rate),
];
rsx! {
DiffViewer {
files: files,
wrap: true,
on_decide: move |(hunk, d)| save(hunk, d),
on_send: move |comments| agent.reply_to(comments),
}
}Rendered from Rust at build time · goes live when visible
When to use
- The agent changed code.
- The user wants to read the change quickly, decide hunk by hunk what stays, tell the agent what to fix, and move on — while the agent may still be writing.
- The diff viewer is the place where trust in an agent's edits is built or lost, so it must be fast on 10,000-line files, never jump under the reader, and make "keep", "undo" and "comment" one key each.
When not to use
- One tool call in one line: use Tool call instead.
- A turn's tool calls grouped the way a transcript reads them: use Tool stack instead.
- Markdown that renders correctly while it streams: use Streaming markdown instead.
Installation
Diff viewer is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add diff-vieweruse crate::oxyn::{DiffViewer, STATUS_INDICATOR_CSS};Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{DiffViewer, STATUS_INDICATOR_CSS};
Usage
let files = vec![
FileDiff::new("src/auth.rs", old_auth, new_auth),
FileDiff::new("src/rate.rs", "", new_rate),
];
rsx! {
DiffViewer {
files: files,
wrap: true,
on_decide: move |(hunk, d)| save(hunk, d),
on_send: move |comments| agent.reply_to(comments),
}
}Examples
Unified
One column with two gutters, file list, minimap and the review bar.
@@ -1,9 +1,11 @@+4 −2@@ -15,5 +17,6 @@fn check+1@@ -1,11 +1,18 @@struct Session+8 −1@@ -0,0 +1,14 @@+14@@ -1,2 +0,0 @@−2Code
let files = vec![
FileDiff::new("src/auth.rs", old_auth, new_auth),
FileDiff::new("src/rate.rs", "", new_rate),
];
rsx! {
DiffViewer {
files: files,
wrap: true,
on_decide: move |(hunk, d)| save(hunk, d),
on_send: move |comments| agent.reply_to(comments),
}
}Split
Old on the left, new on the right; hatched fillers for unpaired rows.
@@ -1,9 +1,11 @@+4 −2@@ -15,5 +17,6 @@fn check+1@@ -1,11 +1,18 @@struct Session+8 −1@@ -0,0 +1,14 @@+14@@ -1,2 +0,0 @@−2Code
let files = vec![
FileDiff::new("src/auth.rs", old_auth, new_auth),
FileDiff::new("src/rate.rs", "", new_rate),
];
rsx! {
DiffViewer {
files: files,
layout: "split",
wrap: true,
on_decide: move |(hunk, d)| save(hunk, d),
on_send: move |comments| agent.reply_to(comments),
}
}Stacked
A Before block over an After block per hunk, for narrow panels.
@@ -1,9 +1,11 @@+4 −2@@ -15,5 +17,6 @@fn check+1@@ -1,11 +1,18 @@struct Session+8 −1@@ -0,0 +1,14 @@+14@@ -1,2 +0,0 @@−2Code
let files = vec![
FileDiff::new("src/auth.rs", old_auth, new_auth),
FileDiff::new("src/rate.rs", "", new_rate),
];
rsx! {
DiffViewer {
files: files,
layout: "stacked",
wrap: true,
on_decide: move |(hunk, d)| save(hunk, d),
on_send: move |comments| agent.reply_to(comments),
}
}Applied
Edits already on disk: Keep / Undo instead of Accept / Reject.
@@ -1,9 +1,11 @@+4 −2@@ -15,5 +17,6 @@fn check+1@@ -1,11 +1,18 @@struct Session+8 −1@@ -0,0 +1,14 @@+14@@ -1,2 +0,0 @@−2Code
let files = vec![
FileDiff::new("src/auth.rs", old_auth, new_auth),
FileDiff::new("src/rate.rs", "", new_rate),
];
rsx! {
DiffViewer {
files: files,
mode: ReviewMode::Applied,
wrap: true,
on_decide: move |(hunk, d)| save(hunk, d),
on_send: move |comments| agent.reply_to(comments),
}
}Bar style
Stripe-only change marks for dense IDE panels.
@@ -1,9 +1,11 @@+4 −2@@ -15,5 +17,6 @@fn check+1@@ -1,11 +1,18 @@struct Session+8 −1@@ -0,0 +1,14 @@+14@@ -1,2 +0,0 @@−2Code
let files = vec![
FileDiff::new("src/auth.rs", old_auth, new_auth),
FileDiff::new("src/rate.rs", "", new_rate),
];
rsx! {
DiffViewer {
files: files,
change_style: "bars",
wrap: true,
on_decide: move |(hunk, d)| save(hunk, d),
on_send: move |comments| agent.reply_to(comments),
}
}Focus dim
Only the current hunk is at full strength.
@@ -1,9 +1,11 @@+4 −2@@ -15,5 +17,6 @@fn check+1Code
let files = vec![
FileDiff::new("src/auth.rs", old_auth, new_auth),
FileDiff::new("src/rate.rs", "", new_rate),
];
rsx! {
DiffViewer {
files: files,
wrap: true,
focus_dim: true,
on_decide: move |(hunk, d)| save(hunk, d),
on_send: move |comments| agent.reply_to(comments),
}
}API reference
DiffViewer
| Prop | Type | Default | Description |
|---|---|---|---|
filesrequired | Vec<FileDiff> | — | Files in first-touch order. |
mode | ReviewMode | Default::default() | `Proposed` (Accept / Reject) or `Applied` (Keep / Undo). |
layout | String | "unified" | `unified` · `split` · `stacked`. |
change_style | String | "background" | `background` · `markers` · `bars`. |
file_list | bool | true | File list on the left. |
word_diff | bool | true | Word-level highlights on paired lines. |
wrap | bool | Default::default() | Wrap long lines. |
line_numbers | bool | true | Line-number gutters. |
minimap | bool | true | Overview ruler at the end edge. |
comments | bool | true | Line comments. |
focus_dim | bool | Default::default() | Dim every hunk but the current one. |
switcher | bool | true | Layout switcher in the header. |
title | String | "Changes" | Heading. |
on_decide | EventHandler<(HunkRef, Decision)> | — | A hunk was decided (`Pending` = restored). |
on_send | EventHandler<Vec<LineComment>> | — | Comments sent to the agent. |
on_viewed | EventHandler<(usize, bool)> | — | A file's Viewed mark changed. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| jork | Next / previous hunk |
| [or] | Previous / next file |
| yorx | Accept (Keep) / Reject (Undo) the current hunk |
| c | Comment on the current hunk; ⌘↵ adds it, Esc closes |
| z | Undo the last decision |
| ⌘↵ | Send every draft comment to the agent |
Accessibility
- Every changed line starts with a hidden “Added:” or “Removed:”, so the diff never relies on the tint; the + and − signs carry it on screen too.
- Hunk buttons name their hunk (“Accept fn login”) and carry aria-keyshortcuts; each decision updates a polite status line that says how many hunks remain.
- The layout switch is a radio group; Viewed is a real checkbox; the file list marks the current file with aria-current.
- Reduced motion drops the chip pop, row fades and the smooth scroll to the next hunk.
From the spec
- Structure. Viewer is a
region"Changes, 4 files, 58 lines added, 21 removed". File list is atree(orlistboxwhen flat). Each file is aregionlabelled by its header; each hunk is agroup"Hunk 2 of 5 in auth.rs, lines 40 to 52, 1 added 1 removed, pending". Lines are rows in agrid(split: two cells per row) so screen readers can move by line and by column. - Line names. "Line 41, added: let ok = verify(pw, &user.salt)?" and for paired lines a summary of the word change on request (
ireads "changed check to verify, added user.salt") — never only colour. - Keyboard. All single-letter keys work only when focus is inside the viewer and not in a text field; every key has a menu equivalent;
?opens the shortcuts sheet. j/k hunks, n/p or ]/[ files, ↑/↓ lines, Shift+↑/↓ extend selection for comments, y/u decide, r restore, c comment, ⌘↩ send comments, v viewed, s layout, w wrap, e expand/collapse all, x expand context, f follow, o open in editor, Esc closes the comment composer then the viewer. - Live region (polite): decisions ("Hunk kept. 3 of 12 remaining."), bulk results ("Kept 12 hunks in 4 files."), streaming start / finish per file once ("Agent is editing session.rs" / "Finished editing session.rs, 30 added, 15 removed"), comments sent. Rolling counts are never announced per tick. Conflicts and write failures assertive once.
- Focus. Auto-advance moves focus only if focus was on the decided hunk; it never steals focus from a comment composer or the file list. After bulk actions focus stays on the button.
- Contrast. Code text on tints ≥ 4.5:1 (auto-corrected, §2.3); word highlights ≥ 3:1 against the row tint plus an underline in high-contrast mode;
+/−signs always present; minimap marks are decorative (their information is in the file list and review bar). - Colour-blind.
daltonizedtoken preset (checkpoints-git.md §5.2). - Reduced motion. §6 last row.
Motion & interaction
- Hunk focus. j/k move a 2 px focus outline (
spring.snap, 160 ms) and scroll the hunk to the upper third (ease.out200 ms); the review bar counter rolls "Hunk 3 → 4 of 12". - Action reveal. On hover or focus, hunk actions fade in (120 ms); they reserve their space in the header, so nothing shifts. On touch and in IDE density they are always visible.
- Keep. Rows' tint fades to neutral (
dur.hunk.resolve, 240 msease.out); the action group morphs into a "Kept ✓" chip (160 msspring.snap, ✓ stroke 240 ms); the file's progress glyph advances (○ → ◐ → ●) and the header counts update (+12 −3→ "+8 −2 of +12 −3" in partially-kept files, file-edit-chip.md format). Focus jumps to the next pending hunk after 120 ms (proposedauto_advance, on by default; Windsurf's count updates as you accept one by one, note 08 §1.13). - Undo. Added lines get a strike drawn start → end (200 ms) and dim to 50 %; removed lines lose their tint and become context; after
delay.auto_collapse(1200 ms) the hunk collapses to its header (dur.collapse) with "Undone · Restore". Restore plays it back. - Bulk (Keep all / Undo all). Hunks resolve in document order with
stagger.bulk(30 ms, cap 8 — the rest resolve together); off-screen hunks resolve instantly; the review bar shows progress. Undo all on applied changes spanning > 1 file asks an inline confirm in the review bar ("Undo 12 hunks in 4 files? Undo · Cancel") — no modal. - Comment. Hover a line shows a "+" in the gutter (Claude desktop pattern, note 03); click or
copens an inline comment composer under the line (dur.expand); Shift+click or Shift+↑/↓ extends to a range (Hoplite range comments, note 10), the range gets a 2 px accent bar in the gutter. Drafts batch; ⌘↩ sends all; on send, threads collapse to a 💬 chip with "Sent" and the agent's replies appear in them. - Layout switch. 160 ms crossfade between layouts (
dur.layout.switch), the focused hunk (or the line under the pointer) keeps its screen position (scroll anchoring). - Context expand. Gap row opens to the requested lines with
dur.context.expand(180 msspring.snap), content above fixed. - Streaming. Lines fade in (120 ms); the write head bar slides to the next line (80 ms
ease.out); hunk counts roll; a file finishing writing gets a single 600 msdur.highlight.fade-style header wash. - Viewed. Ticking Viewed draws the check, collapses the file (
dur.collapse) and the "2 of 4 viewed" counter rolls; the file list row dims to 70 %. - Minimap. Viewport box follows scroll at 60 Hz; hover over a mark shows a tooltip ("Hunk 7 · +4 −1 · 2 comments") after 200 ms.
- Failure. Chip morphs to ✕ with the tools.md error nudge on the glyph only; rows never shake.
Timing
| Transition | Duration | Delay | Easing / spring | Stagger | Frame rate |
|---|---|---|---|---|---|
| Loading skeleton | — | 150 ms | — | — | 30 Hz shimmer |
| Hunk focus outline + scroll | 160 ms + 200 ms | 0 | spring.snap / ease.out | — | 60 Hz |
| Action reveal | 120 ms | 0 (hover) | ease.out | — | 60 Hz |
| Keep: tint fade + chip morph + ✓ | 240 + 160 + 240 ms | 0 | ease.out / spring.snap | — | 60 Hz |
| Auto-advance to next hunk | as focus | 120 ms after decision | ease.out | — | 60 Hz |
| Undo strike + dim | 200 ms | 0 | ease.out | — | 60 Hz |
| Undone collapse | 280 ms (dur.collapse) | 1200 ms | ease.in | — | 60 Hz |
| Bulk cascade | 240 ms each | 0 | ease.out | 30 ms, cap 8 | 60 Hz |
| Comment composer open / close | 220 ms / 280 ms | 0 | spring.snap / ease.in | — | 60 Hz |
| Layout switch | 160 ms crossfade | 0 | ease.in-out | — | 60 Hz |
| Context expand | 180 ms | 0 | spring.snap | — | 60 Hz |
| Streaming line enter | 120 ms opacity | 0 | ease.out | batched ≤ 30 Hz | 30 Hz |
| Write head move | 80 ms | 0 | ease.out | — | 60 Hz |
| Follow scroll | 200 ms, ≤ 1 per 250 ms | 0 | ease.out | — | 60 Hz |
| Count roll (hunk / file / review bar) | 280 ms | 0 | ease.out | 30 ms digits | 30 Hz |
| File done wash | 600 ms | 0 | ease.out | — | 30 Hz |
| Viewed collapse | 280 ms | after ✓ 240 ms | ease.in | — | 60 Hz |
| Minimap tooltip | 140 ms | 200 ms | ease.out | — | 60 Hz |
| Send label swap / "Sent ✓" hold | 120 ms / 600 ms | 0 | ease.out | — | 60 Hz |
| Reduced motion | no scroll animation (jump), no outline spring (outline appears), keep / undo swap tint and chip with an 80 ms crossfade, no strike draw (strike appears), no cascade (bulk resolves at once), layout switch instant with anchoring kept, streaming lines appear without fade and follow jumps at most once per 1 s, no washes (2 px static bar for 2 s), counts swap | — | linear | none | event-driven |
Responsive behaviour
- Container query: under 640 px the file list becomes a sideways strip, the minimap hides and comments lose their indent.
- Long lines scroll inside the diff (or wrap with Wrap); the file header stays pinned while you scroll a file.
Edge cases (spec)
- Huge change sets (500+ files): file list virtualised; diff body is one virtualised scroll; files load lazily as they approach the viewport (± 2 screens); first paint budget < 100 ms for the visible region (proposed).
- Very fast agents. A file that streams and settles inside
delay.row_guard(150 ms) renders settled with no streaming state. - Very slow agents. A streaming file with no new lines for
tool_stall(120 s, tools.md) shows "No changes for 2 min" in its header; the write head stops (no looping animation). - Edits arrive while reviewing. New hunks in already-decided files mark the file ◐ again and enter with a 1600 ms
dur.highlight.fadetint; decisions already made are kept unless the new edit overlaps a decided hunk, which then becomesEdited(agent version) and asks for review again. - User edits the file outside the viewer. Overlapping hunks →
Conflict(Resolve opens merge-conflict.md); non-overlapping hunks re-anchor silently. - Proposed-mode timeouts. If the approval behind a proposed edit is cancelled (run stopped), the diff becomes
ReadOnlywith "Edit was cancelled". - Checkpoint preview / replay. Viewer renders
ReadOnlywith the snapshot-banner context; all decision keys are inert and announce "Viewing a past state". - Long lines with wrap off. Horizontal scroll per file (split: both panes scroll together); wrap on: continuation rows get a
↪in the gutter and no line number. - Tabs vs spaces. Tabs render at the host's tab width (default 4, proposed); whitespace-only diffs can be hidden (§2.2).
- RTL UI. Chrome mirrors (file list moves to the end edge, review bar order mirrors); code, gutters, line numbers and the split old/new order stay LTR (old left, new right) in a bidi isolate. RTL text inside code lines renders per Unicode bidi but word-diff marks follow logical order.
- Tiny sizes. Under 360 px only
stackedis offered; under 240 px the viewer opens as a full-screen sheet; file list becomes a dropdown; minimap hidden under 480 px. - Dense IDE panels. 18 px rows, 12 px mono, actions as icons with tooltips, always visible; hunk headers 20 px.
- Touch. 44 px targets for actions (header grows, rows don't); long-press a line to comment; two-finger horizontal scroll inside code;
hunk-cardsfor swipe review. - Slow networks / remote host. Skeleton after 150 ms; files stream in as they load; decisions queue locally and show
Applyinguntil the host confirms; offline →ReadOnlywith queued comments kept as drafts. - Secrets. Lines the adapter marks redacted render as
••••with "Redacted" in the gutter; copy excludes them. - Copy semantics. Copying from
unified/splitcopies the new side's text without signs or line numbers by default; Alt-copy copies the patch.
Notes for AI
- Import
DiffViewerfromoxyn_dioxusand includeSTATUS_INDICATOR_CSSplus the token stylesheet once. - A GPUI version exists:
DiffViewerElinoxyn_gpui. - Props to set first:
files. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.