Browse documentation

Code editor

Edit large source buffers with syntax highlighting and viewport-only shaping.

Import

Load the optional component layer before using the examples below.

Ruby
require "zaniah/ui"

Basic editor

Pass a string or a line-addressable buffer. Specify language: for bundled syntax scopes.

Rendered example
Ruby code editor next to styled rich text.
Rendered by Zaniah's headless backend.
Ruby
Zaniah::UI::CodeEditor.new(
  "def hello\n  :world\nend\n",
  language: :ruby, line_numbers: true)

Buffer and highlighting

A custom buffer exposes line_count, line, line_start, line_of, replace, undo, and redo. An optional highlighter returns scoped token ranges.

API summary

Constructor options and behaviors are drawn from the component reference.

ComponentConstructor and methodsVariants or behavior
CodeEditor(value, buffer:, highlighter:, wrap:, language:, line_numbers:, read_only:); on_changeviewport-only multiline editor with syntax scopes and Tab indentation

Accessibility

CodeEditor exposes a multiline textbox with keyboard selection, IME, Tab indentation, and undo/redo.

ComponentSemantic role
CodeEditortextbox