Skip to main content

Module code_editor

Module code_editor 

Source
Expand description

Multi-line plain-text and code editing surfaces.

Three faces over one core:

  • CodeEditor — a source editor: gutter, current-line highlight, indentation, bracket handling, multiple carets.
  • PlainTextEditor — the same core with the code affordances off and wrapping on: a notes field, a commit message, a description box.
  • LogView — read-only, append-only, tail-following.

They are one implementation because they differ in configuration, not in kind. All three are a monospaced-or-not run of lines with a caret in it; a separate widget per face would triplicate the caret, selection, IME, clipboard, scrolling, and accessibility and let them drift.

§Why not RichTextEditor

RichTextEditor already edits multi-line text, and this deliberately does not build on it. Its command vocabulary is tables, lists, blockquotes, and bold — reusing it would put Tab-navigates-a-table-cell and Ctrl+B-emboldens into a source file, where the first is wrong and the second is meaningless. Its state carries a table-aware Ctrl+A ladder and a rich clipboard fragment; this one carries an indent policy and a caret vector. The overlap is real but it is the clock — the caret blink, the debounce window, the scroll arithmetic — and that lives in the crate-internal common::editor_runtime, shared by both.

§Language-agnostic by construction

There is no Language enum here. Comment tokens, bracket pairs, indent width, and highlighting are CodeConfig values the application supplies: the editor knows how to toggle a line comment, not that Rust uses //. Guessing would be worse than not knowing — inserting // into a Python file corrupts it silently.

Structs§

BracketPair
A pair of characters the editor treats as opening and closing delimiters.
CodeConfig
Editing behaviour the code editor applies, all supplied by the application.
CodeEditor
A multi-line source-code editing surface: gutter, current-line highlight, indentation, bracket handling, and multiple carets.
CodeEditorHandle
A handle onto a live editor, cloneable and detachable from the widget.
CompletionContext
What a completion provider is told about the caret when asked for candidates.
CompletionItem
A completion candidate. Build with CompletionItem::new and the fluent setters; insert_text defaults to label.
LogView
A read-only, append-only, tail-following log / console view.
LogViewHandle
A cloneable handle to append to a LogView and drive it.
PlainTextEditor
A multi-line plain-text editing surface — the code editor with its code affordances off and wrapping on. A notes field, a commit message, a description box.

Enums§

CodeCommand
Commands the code editor’s keyboard layer may emit.
CompletionKind
The category of a completion candidate — drives a small leading badge only. Deliberately a fixed, language-neutral set: the editor renders a glyph, the application decides which candidate is which kind.
IndentStyle
How a line’s leading indentation is written.

Constants§

CODE_EDITOR_PRESET
The editable preset, shared by CodeEditor::new and PlainTextEditor::new: every command accepted, blinking caret, MultilineTextInput role, full clipboard.
CODE_READ_ONLY_PRESET
The read-only preset for CodeEditor::read_only / PlainTextEditor::read_only and for a streaming log view.
COMMON_BRACKETS
The three pairs that are structural in essentially every bracketed language. A convenience starting point, not a default — an editor with no configured pairs simply does no bracket handling, which is correct for prose or a log.