$ rezi
Widgets

DiffViewer

Renders unified or side-by-side diffs with hunk navigation.

Renders unified or side-by-side diffs with hunk navigation.

Usage

ui.diffViewer({
  id: "diff",
  diff: state.diff,
  mode: "unified",
  scrollTop: state.scrollTop,
  lineNumbers: true,
  contextLines: 3,
  onScroll: (top) => app.update((s) => ({ ...s, scrollTop: top })),
  onStageHunk: (i) => stageHunk(i),
  onRevertHunk: (i) => revertHunk(i),
})

Props

PropTypeDefaultDescription
idstringrequiredWidget identifier
diffDiffDatarequiredDiff data model
mode"unified" | "sideBySide"requiredRender mode
scrollTopnumberrequiredScroll offset (lines)
lineNumbersbooleantrueShow line numbers
contextLinesnumber3Context lines around changes
expandedHunksnumber[]-Hunks expanded beyond default threshold
focusedHunknumber-Focused hunk index
onScroll(scrollTop) => voidrequiredScroll callback
onHunkToggle(index, expanded) => void-Expand/collapse callback
onStageHunk(index) => void-Stage callback
onUnstageHunk(index) => void-Unstage callback
onApplyHunk(index) => void-Apply callback
onRevertHunk(index) => void-Revert callback

Mouse Behavior

  • Mouse scroll wheel scrolls diff content, firing the onScroll callback.
  • Clicking the viewer area focuses the widget.

Notes

  • DiffData includes file paths, hunks, and optional binary flag.
  • Provide expandedHunks to keep large hunks open by default.

On this page