Skip to content

Editor

A retained native code editor with syntax coloring, line numbers, indentation, and both-axis scrolling.

No language grammars are included by default. Register a linked grammar in Rust, or load one portable pack of selected Tree-sitter Wasm grammars and queries using loadLanguagePack (TypeScript) / LoadLanguagePack (Go).

Unstyled by default: text and line-number colors inherit, and the component adds no background, border, rounding, padding, or syntax/diff palette. Supply application styles and explicit colors to opt into an appearance.

#Import

Enable QuickGUI's opt-in editor crate feature and import the retained editor types.

use quickgui::{Editor, IntoElement, SyntaxLanguage, View, ViewContext};

#Usage

struct EditorExample {
    editor: Editor,
}

impl View for EditorExample {
    fn render(&mut self, cx: &mut ViewContext<'_, Self>) -> impl IntoElement {
        let changed = cx.input_listener("source", |view, value, cx| {
            if view.editor.set_text(value).changed {
                cx.invalidate();
            }
        });
        self.editor.element("source").on_input(changed)
    }
}

#Syntax highlighting

SyntaxLanguage selects a registered Tree-sitter grammar and highlight query. Query captures are flattened into eight stable SyntaxTheme classes and applied as foreground-only HighlightStyle spans, so color never changes text metrics. Source or language changes reparse the bounded document; palette changes only remap the retained captures, and scrolling does no syntax work. Parsing is limited to 2 MiB, individual lines over 32 KiB stay plain, and the capture count is capped. This is structural syntax highlighting, not language-server semantic tokens.

#API reference

Expand an entry for its description and complete signature. A dash means no declaration default is documented.

pub fn new() -> Self
with_textpub fn with_text(source: &str) -> Self—

Configures with text for this part.

pub fn with_text(source: &str) -> Self
View source
with_languagepub fn with_language(mut self, language: SyntaxLanguage) -> Self—

Configures with language for this part.

pub fn with_language(mut self, language: SyntaxLanguage) -> Self
View source
with_stylepub fn with_style(mut self, style: EditorStyle) -> Self—

Configures with style for this part.

pub fn with_style(mut self, style: EditorStyle) -> Self
View source
with_behaviorpub fn with_behavior(mut self, behavior: TextInputIndentation) -> Self—

Configures with behavior for this part.

pub fn with_behavior(mut self, behavior: TextInputIndentation) -> Self
View source
textpub fn text(&self) -> &str—

Configures text for this part.

pub fn text(&self) -> &str
View source
languagepub const fn language(&self) -> SyntaxLanguage—

Configures language for this part.

pub const fn language(&self) -> SyntaxLanguage
View source
stylepub const fn style(&self) -> EditorStyle—

Configures style for this part.

pub const fn style(&self) -> EditorStyle
View source
behaviorpub const fn behavior(&self) -> TextInputIndentation—

Configures behavior for this part.

pub const fn behavior(&self) -> TextInputIndentation
View source
is_truncatedpub const fn is_truncated(&self) -> bool—

Configures is truncated for this part.

pub const fn is_truncated(&self) -> bool
View source
set_textpub fn set_text(&mut self, source: &str) -> EditorUpdate—

Configures set text for this part.

pub fn set_text(&mut self, source: &str) -> EditorUpdate
View source
set_languagepub fn set_language(&mut self, language: SyntaxLanguage) -> bool—

Configures set language for this part.

pub fn set_language(&mut self, language: SyntaxLanguage) -> bool
View source
set_stylepub fn set_style(&mut self, style: EditorStyle) -> bool—

Configures set style for this part.

pub fn set_style(&mut self, style: EditorStyle) -> bool
View source
set_behaviorpub fn set_behavior(&mut self, behavior: TextInputIndentation) -> bool—

Configures set behavior for this part.

pub fn set_behavior(&mut self, behavior: TextInputIndentation) -> bool
View source
set_read_onlypub fn set_read_only(&mut self, read_only: bool) -> bool—

Configures set read only for this part.

pub fn set_read_only(&mut self, read_only: bool) -> bool
View source
refresh_syntax_languagespub fn refresh_syntax_languages(&mut self) -> bool—

Refresh captures after registering a grammar used by this document or an injection. Returns false without parsing when the registry is unchanged; preserves editing state.

pub fn refresh_syntax_languages(&mut self) -> bool
View source

Editor::element

View source
pub fn element(&self, id: impl Into<ElementId>) -> Element

Build the editor leaf. Attach a stable [`crate::InputListener`] with [`Element::on_input`](crate::Element::on_input).