Skip to content

code/editor/DiffView

import { … } from 'zidane-ui/code/editor'ui/src/code/editor/DiffView.tsx

Components#

DiffScrollerComponent#

pierre's virtualizer as the scroll box of a list of diffs: every DiffView inside renders only its lines near the viewport, so a large change set opens and scrolls in frames.

TypeScript
function DiffScroller(props: DiffScrollerProps): Element
Parameters
NameTypeDescription
propsDiffScrollerProps

The scroll box's and content box's classes, and the diffs.

Element
DiffScroller props
NameTypeDescription
children?ReactNode

The diffs.

className?string

Classes on the scroll box.

contentClassName?string

Classes on the content box inside it.

ui/src/code/editor/DiffView.tsx:191

DiffViewComponent#

One file's diff, rendered by pierre in the editor environment's theme, with optional line selection and annotation rows.

TypeScript
function DiffView<A>(props: DiffViewProps<A>): Element
Type parameters
NameDescription
A
Parameters
NameTypeDescription
propsDiffViewProps<A>

The patch or parsed diff, the style, and the selection and annotation hooks.

Element
DiffView props
NameTypeDescription
annotations?readonly DiffLineAnnotation<A>[]

Rows under lines (review comments).

className?string

Classes on pierre's host element.

diffStyle?DiffStyle

Unified or split. Default unified.

fileDiff?FileDiffMetadata

An already-parsed file diff (wins over patch).

hideHeader?boolean

Hide the per-file header (when the caller renders its own).

onContextMenu?(e: MouseEvent<HTMLDivElement>) => void

Right-click anywhere in the view (the host element, so shadow paths are intact).

onGutterAction?(range: SelectedLineRange) => void

Gutter "+" on hover / at the selection end; called with the range it covers.

onSelectionEnd?(range: SelectedLineRange | null) => void

A line range was selected (enables selection).

patch?string

Unified patch for exactly one file.

renderAnnotation?(annotation: DiffLineAnnotation<A>) => ReactNode

Renders one annotation row.

selectedLines?SelectedLineRange | null

The selected line range (controlled).

wrap?boolean

Wrap long lines instead of scrolling.

ui/src/code/editor/DiffView.tsx:173

Interfaces#

DiffScrollerPropsInterface#

Props for DiffScroller.

TypeScript
interface DiffScrollerProps
DiffScrollerProps properties
NameTypeDescription
children?ReactNode

The diffs.

className?string

Classes on the scroll box.

contentClassName?string

Classes on the content box inside it.

ui/src/code/editor/DiffView.tsx:176

DiffViewPropsInterface#

Props for DiffView.

TypeScript
interface DiffViewProps<A = unknown>
DiffViewProps type parameters
NameDefaultDescription
Aunknown
DiffViewProps properties
NameTypeDescription
annotations?readonly DiffLineAnnotation<A>[]

Rows under lines (review comments).

className?string

Classes on pierre's host element.

diffStyle?DiffStyle

Unified or split. Default unified.

fileDiff?FileDiffMetadata

An already-parsed file diff (wins over patch).

hideHeader?boolean

Hide the per-file header (when the caller renders its own).

onContextMenu?(e: MouseEvent<HTMLDivElement>) => void

Right-click anywhere in the view (the host element, so shadow paths are intact).

onGutterAction?(range: SelectedLineRange) => void

Gutter "+" on hover / at the selection end; called with the range it covers.

onSelectionEnd?(range: SelectedLineRange | null) => void

A line range was selected (enables selection).

patch?string

Unified patch for exactly one file.

renderAnnotation?(annotation: DiffLineAnnotation<A>) => ReactNode

Renders one annotation row.

selectedLines?SelectedLineRange | null

The selected line range (controlled).

wrap?boolean

Wrap long lines instead of scrolling.

ui/src/code/editor/DiffView.tsx:34

Types#

DiffStyleType#

One column with removals above additions, or two side by side.

TypeScript
type DiffStyle = 'unified' | 'split'

ui/src/code/editor/DiffView.tsx:28

Re-exports#

These names are documented on the entry point that owns them.

  • DiffLineAnnotation
  • FileDiffMetadata
  • LineAnnotation
  • SelectedLineRange