Module code_editor
Expand description
The shared multi-line code-editing widget: a retained Widget that
puts real code editing — caret, selection (shift/drag, word-wise),
clipboard, undo/redo, IME, and a multiline a11y node — on the same
TextInput core every other text field
uses. On top of that it adds a gutter with line numbers and a
current-line highlight, syntax highlighting through a pluggable
Highlighter (the widget owns rendering/caret/selection, the app
owns the language tokenizer, and every colour comes from the OS
Theme), and soft-tab / indent handling.
use tilo_ui::widget::code_editor::{CodeEditor, Language};
let mut editor = CodeEditor::local()
.with_language(Language::Rust)
.with_tab_width(4);
editor.set_text("fn main() {\n println!(\"hi\");\n}\n");Modules§
- syntax
- The toolkit’s grammar-backed
Highlighter: Sublime syntax definitions run throughsyntect, used purely as a tokenizer. Each span’s scope stack (source.rust → meta.function → entity.name.function) maps to oneTokenKind; colours stay with the renderer and the OSTheme, never with a syntect colour theme.
Structs§
- Code
Editor - Wraps the multiline
TextInputcore and enables its gutter + syntax-highlight path, so all caret/selection/clipboard/undo/IME/a11y behaviour is the one shared implementation. - Diagnostic
- A problem a checker found in the source: a byte
range, how much it matters, and what it says. The editor draws it — a squiggle under the range, a mark in the gutter, the message on hover — in the theme’s status colours; the app only says what is wrong where. - Line
Spans - One logical line’s highlight result: ordered, non-overlapping
Spans (gaps render in the default text colour) plus theHlStatethe next line begins with. - Span
- A coloured run within one logical line: a byte
range(into that line) and itsTokenKind. - Syntax
Highlighter - A grammar-backed
Highlighterfor one language. - Syntax
State - A grammar’s parse position between two lines: everything multi-line constructs (block comments, strings, heredocs) need to continue.
- Typst
Highlighter - A pragmatic Typst highlighter — a per-line lexer recognising headings,
comments, strings,
#-functions, numbers, raw code (inline and fenced), maths,*strong*and_emph_runs. Fenced code blocks are carried across lines.
Enums§
- Language
- A built-in language the editor ships a
Highlighterfor. Any other language with a grammar is aSyntaxHighlighter::for_tokenaway. - Severity
- How much a
Diagnosticmatters. - Token
Kind - The syntactic category a run of source falls into. The editor never
hard-codes a colour for these — the theme’s
SyntaxPaletteresolves each to a concrete colour, so syntax tracks the active theme in light, dark and high contrast.
Traits§
- Highlighter
- A pluggable, per-line source tokenizer. The
CodeEditorowns rendering, caret, and selection; aHighlighterowns only the language lexing — mapping a line of source to colouredSpans.SyntaxHighlightercovers every language with a grammar; hand it (or a wrapper that adds app-specific spans) toCodeEditor::with_highlighter.
Functions§
- paint_
diagnostic_ underline - A wavy underline from
x0tox1alongy: the mark of a problem in text, as spelling marks one.
Type Aliases§
- HlState
- Opaque cross-line carry so multi-line constructs — block comments, fenced
code — survive from one line to the next.
0is the document start; aHighlighterowns the meaning of every other value. Line-local highlighters ignore it and always return0.