Skip to main content

Module code_view

Module code_view 

Source
Expand description

A read-only code view: virtualized lines, a line-number gutter, optional wrapping, mouse selection with copy, search marks, and syntax colours from ashlar_syntax.

A frame costs O(visible lines). The line index and the lexer state at the start of each line are kept per (id, revision); line states are computed lazily up to the lowest line shown. Each line’s galley is cached by (id, line) and rebuilt only when the revision, its start state, the width, the font or the theme changes.

Unwrapped (wrap(false)), lines wider than the view scroll sideways: the horizontal wheel (Shift+wheel) over the view, or a drag on the thin bar along its bottom.

let out = CodeView::new("editor.preview", source).lang_for_path("src/main.rs").revision(revision).wrap(false).show(ui);
if out.copied {
    // the selection is on the clipboard
}

Automation: the view registers as <id> (a document) and each visible line as <id>.line.<n> (1-based, labelled with its text). AccessKit: the view is a read-only document, each visible line a paragraph labelled with its text.

Structs§

CodeView
A read-only, virtualized code view. See the module docs.
CodeViewResponse
What the view reports this frame.
SyntaxTheme
Colours for each Kind of token.

Functions§

highlight_job
A highlighted layout job for one block of code (used by Markdown code fences): each span becomes a section in font coloured by theme. Unknown languages give one plain section.