Skip to content

code/editor/CodeEditor

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

Components#

CodeEditorComponent#

A file's text, read-only until used and then editable in place; see the module comment for how it arms, saves and finds.

TypeScript
function CodeEditor<A = unknown>(
  props: CodeEditorProps<A> & { ref?: Ref<CodeEditorHandle> },
): Element
Type parameters
NameDefaultDescription
Aunknown
Parameters
NameTypeDescription
propsCodeEditorProps<A> & { ref?: Ref<CodeEditorHandle> }

The document, its session key and the view hooks; ref reaches the CodeEditorHandle.

Element
CodeEditor props
NameTypeDescription
annotations?readonly LineAnnotation<A>[]

Content anchored under lines (review comments); rendered by renderAnnotation.

children?ReactNode

Rendered after the view (a context menu, a hover card).

className?string

Extra classes on the root element.

docCodeDocument

The file's state from useCodeDocument: text, draft, dirty and conflict flags, save and discard.

findAsk?number

Bumps on ⌘F; the visible editor opens find.

hostAttributes?Record<string, string | undefined>

Extra attributes on the host (data-* states the owner styles).

markers?readonly Marker[]

Squiggles with hover messages, while editing.

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

Right-click anywhere in the view.

onGutterAction?(range: SelectedLineRange) => void

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

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

Gutter line selection finished; passing it turns line selection on.

onTokenClick?(token: CodeToken, event: MouseEvent) => void

Click on an identifier (Cmd/Ctrl-click for go to definition).

onTokenEnter?(token: CodeToken, event: PointerEvent) => void

The pointer moved onto an identifier (for hovers and the definition underline).

onTokenLeave?() => void

The pointer left the identifier it entered.

pathstring

Display name; the language is inferred from its extension.

readOnly?boolean

Never arm the editor, even with the Editor setting on.

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

Renders one entry of annotations.

scrollerClassName?string

The scroll container's classes (the view virtualises its lines).

selectedLines?SelectedLineRange | null

The selected line range, controlled by the owner; needs onSelectionEnd.

sessionKeystring

pierre's retained-session key (the draft and undo stack survive remounts under it).

style?CSSProperties

Inline styles on the root element, merged after the component's own.

visible?boolean

Whether this editor is on screen (default true): it takes focus when it becomes visible, arms on idle and answers ⌘F only then.

ref?Ref<CodeEditorHandle>

Receives the CodeEditorHandle.

ui/src/code/editor/CodeEditor.tsx:425

Interfaces#

CodeEditorHandleInterface#

What a CodeEditor ref reaches.

TypeScript
interface CodeEditorHandle
CodeEditorHandle properties
NameTypeDescription
editor() => Editor<'file', unknown, undefined> | null

The armed editor, null while read-only.

host() => HTMLDivElement | null

The editor's outer element (holds the scroller and pierre's <diffs-container>), null before mount.

placeCaret(caret: { character: number; lineNumber: number }) => void

Put the caret there: focuses the editor, arming it first when needed.

ui/src/code/editor/CodeEditor.tsx:57

CodeEditorPropsInterface#

Props of CodeEditor; A is the annotation payload type.

TypeScript
interface CodeEditorProps<A>
CodeEditorProps type parameters
NameDescription
A
CodeEditorProps properties
NameTypeDescription
annotations?readonly LineAnnotation<A>[]

Content anchored under lines (review comments); rendered by renderAnnotation.

children?ReactNode

Rendered after the view (a context menu, a hover card).

className?string

Extra classes on the root element.

docCodeDocument

The file's state from useCodeDocument: text, draft, dirty and conflict flags, save and discard.

findAsk?number

Bumps on ⌘F; the visible editor opens find.

hostAttributes?Record<string, string | undefined>

Extra attributes on the host (data-* states the owner styles).

markers?readonly Marker[]

Squiggles with hover messages, while editing.

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

Right-click anywhere in the view.

onGutterAction?(range: SelectedLineRange) => void

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

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

Gutter line selection finished; passing it turns line selection on.

onTokenClick?(token: CodeToken, event: MouseEvent) => void

Click on an identifier (Cmd/Ctrl-click for go to definition).

onTokenEnter?(token: CodeToken, event: PointerEvent) => void

The pointer moved onto an identifier (for hovers and the definition underline).

onTokenLeave?() => void

The pointer left the identifier it entered.

pathstring

Display name; the language is inferred from its extension.

readOnly?boolean

Never arm the editor, even with the Editor setting on.

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

Renders one entry of annotations.

scrollerClassName?string

The scroll container's classes (the view virtualises its lines).

selectedLines?SelectedLineRange | null

The selected line range, controlled by the owner; needs onSelectionEnd.

sessionKeystring

pierre's retained-session key (the draft and undo stack survive remounts under it).

style?CSSProperties

Inline styles on the root element, merged after the component's own.

visible?boolean

Whether this editor is on screen (default true): it takes focus when it becomes visible, arms on idle and answers ⌘F only then.

ui/src/code/editor/CodeEditor.tsx:67