$ rezi
Widgets

CodeEditor

Code-oriented text editor widget (cursor, selection, search, and scrolling).

Code-oriented text editor widget (cursor, selection, search, and scrolling).

Usage

ui.codeEditor({
  id: "editor",
  lines: state.lines,
  cursor: state.cursor,
  selection: state.selection,
  scrollTop: state.scrollTop,
  scrollLeft: state.scrollLeft,
  lineNumbers: true,
  tabSize: 2,
  onChange: (lines, cursor) => app.update((s) => ({ ...s, lines, cursor })),
  onSelectionChange: (sel) => app.update((s) => ({ ...s, selection: sel })),
  onScroll: (top, left) => app.update((s) => ({ ...s, scrollTop: top, scrollLeft: left })),
})

Props

PropTypeDefaultDescription
idstringrequiredWidget identifier
linesstring[]requiredDocument content (lines)
cursor{ line: number; column: number }requiredCursor position (0-based)
selectionEditorSelection | nullrequiredSelection range
scrollTopnumberrequiredVertical scroll (lines)
scrollLeftnumberrequiredHorizontal scroll (columns)
tabSizenumber2Tab width
insertSpacesbooleantrueInsert spaces instead of tabs
lineNumbersbooleantrueShow line numbers
wordWrapbooleanfalseWrap long lines
readOnlybooleanfalseRead-only mode
searchQuerystring-Search text
searchMatchesSearchMatch[]-Match ranges
currentMatchIndexnumber-Highlighted match
diagnostics{ range: { start: { line: number; column: number }; end: { line: number; column: number } }; severity?: "error" | "warning" | "info" | "hint"; message?: string }[]-Inline diagnostics rendered with curly underlines
onChange(lines, cursor) => voidrequiredContent change callback
onSelectionChange(selection) => voidrequiredSelection change callback
onScroll(scrollTop, scrollLeft) => voidrequiredScroll callback
onUndo() => void-Undo callback
onRedo() => void-Redo callback

Mouse Behavior

  • Mouse scroll wheel scrolls the editor vertically and horizontally, firing the onScroll callback.
  • Clicking the editor area focuses the widget.

Keyboard Clipboard

  • Ctrl+C copies the active selection to system clipboard via OSC 52.
  • Ctrl+X cuts the active selection (when readOnly !== true) and writes it to system clipboard via OSC 52.

Notes

  • lines is the source of truth; update it in onChange to keep the editor controlled.
  • Diagnostic ranges render with themed curly underlines when provided.

On this page