Skip to main content

Module code_editor

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: a [tilo_highlight] grammar set (syntect over two-face’s grammars), each span’s scope mapped to one TokenKind; colours stay with the renderer and the OS Theme, never with a syntect colour theme.
tilolang
tilolang, coloured by its own lexer (tilolang::lexer): what the compiler reads as a keyword, a string, a number, a reference literal (@board.Card:c1) or a comment is what the editor colours as one, so the colours never disagree with the language.

Structs§

CodeEditor
Wraps the multiline TextInput core and enables its gutter + syntax-highlight path, so all caret/selection/clipboard/undo/IME/a11y behaviour is the one shared implementation.
CodeEditorProps
Code to read or write, with line numbers and its language’s colouring. What is typed edits the text it is bound to, each edit spliced in, never written over.
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.
LineSpans
One logical line’s highlight result: ordered, non-overlapping Spans (gaps render in the default text colour) plus the HlState the next line begins with.
Span
A coloured run within one logical line: a byte range (into that line) and its TokenKind.
SyntaxHighlighter
A grammar-backed Highlighter for one language.
SyntaxState
A grammar’s parse position between two lines: everything multi-line constructs (block comments, strings, heredocs) need to continue.
TilolangHighlighter
Colours tilolang source a line at a time. A tilolang string or comment never spans lines, so no state carries from one line to the next.
TypstHighlighter
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 Highlighter for. Any other language with a grammar is a SyntaxHighlighter::for_token away.
Severity
How much a Diagnostic matters.
TokenKind
The syntactic category a run of source falls into. The editor never hard-codes a colour for these — the theme’s syntax palette resolves 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 CodeEditor owns rendering, caret, and selection; a Highlighter owns only the language lexing — mapping a line of source to coloured Spans. SyntaxHighlighter covers every language with a grammar; hand it (or a wrapper that adds app-specific spans) to CodeEditor::with_highlighter.

Functions§

paint_diagnostic_underline
A wavy underline from x0 to x1 along y: 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. 0 is the document start; a Highlighter owns the meaning of every other value. Line-local highlighters ignore it and always return 0.