Skip to main content

Crate zorite_editor

Crate zorite_editor 

Source
Expand description

Zorite’s WYSIWYG (live-preview) markdown editor — and, without a SyntaxStyle installed, its raw-markdown editor. A from-scratch multi-line text editor for GPUI. (The third view, the read-only reader, is the separate zorite-markdown crate — the two engines share nothing, so any markdown behavior added here must be checked there and vice versa. See AGENTS.md “The three views”.)

Host-agnostic — depends only on gpui (+ unicode-segmentation); no gpui-component. Built directly on gpui’s text primitives: an EntityInputHandler for keyboard + IME input, shape_line for per-line text shaping, and a custom Element that lays out + paints the lines, cursor, and selection. The editor auto-grows to its content height (no inner scrollbar), so a host can stack many editors in one scroll view. Editing fundamentals: cursor/selection, undo/redo, IME, soft-wrap, clipboard, spell-check diagnostics (squiggles + suggestion menu).

WYSIWYG mode is EditorState::set_markdown_style plus the block providers (set_block_image_provider & co). Comments reference its feature milestones by code:

  • W1 — inline styling: bold/italic/strike/code/links/wiki-links/tags, markers dimmed in place (markdown_syntax::scan_line).
  • W2 — heading font sizes (variable per-line heights).
  • W4 — block widgets: W4a inline images, W4b fenced code blocks, W4c tables (Word-style editing); mermaid + $$math$$ rasters ride the same widget path.
  • W6 — marker hiding with reveal-on-caret: the painted text drops the syntax markers, and per-row offset maps translate display ↔ source.

Usage: create an EditorState entity and render it; call bind_keys once at startup so the editing actions resolve while it’s focused.

Structs§

AlertIcons
Per-kind SVG asset paths for the alert title icons.
Backspace
Bold
Code
Copy
Cut
Delete
Diagnostic
A flagged span (e.g. a misspelling) to underline. The host (e.g. a spell checker) computes these and feeds them in via EditorState::set_diagnostics. Replacement suggestions are fetched lazily when the user right-clicks the span, via the provider set with EditorState::on_suggest — so detection can stay cheap and run on every edit.
Dismiss
Down
EditorState
End
Home
Indent
Italic
Labels
The editor: text + cursor/selection state, an undo/redo history, plus a cached layout (the wrapped lines from the last paint) for hit-testing + IME. Renders the WYSIWYG view when a markdown SyntaxStyle is installed, the raw-markdown view otherwise. Host-injectable UI labels the editor renders in its context menus and chrome (right-click menu items, the code-block / math Copy chips, the table / “Turn into” menus). The crate stays host-agnostic so it never calls t!(); the app passes localized strings here via EditorState::set_labels. The default is English, keeping the crate usable standalone (and existing tests’ expectations intact).
Left
Newline
Outdent
Paste
Redo
Right
SelectAll
SelectDown
SelectLeft
SelectRight
SelectUp
SelectWordLeft
SelectWordRight
ShowCharacterPalette
Strike
SyntaxStyle
Colors + monospace font for inline markdown styling, supplied by the host so the editor stays theme-agnostic. Install via crate::EditorState::set_markdown_style; absent it, the editor renders plain text (only spell-check underlines).
Underline
Undo
Up
WordLeft
WordRight

Enums§

CellAlign
A table column’s text alignment, for the host-driven alignment toolbar (EditorState::caret_table_align / EditorState::set_caret_table_align).
EditorEvent
Events the editor emits so a host can react. Subscribe with cx.subscribe(&editor, …) — e.g. to re-run spell-check after an edit.
MathAlign
Horizontal alignment of a display $$…$$ block, chosen per-block via a <!-- math:left --> / <!-- math:right --> marker comment on the line directly above it. Center is the default (no marker), matching LaTeX display math; standard Markdown viewers ignore the comment.

Constants§

LINE_HEIGHT_RATIO
Line height as a multiple of the font size. Derived from the editor’s own font (not the ambient window.line_height(), which tracks the host’s UI text style and would leave the caret/rows mismatched against differently-sized editor text). 1.45 for comfortable reading density while typing (1.25 felt cramped, especially stacking several list rows). Public so a host’s scroll math (e.g. Zorite’s click-to-edit caret prediction) can mirror row heights.

Functions§

bind_keys
Bind the editor’s editing keys. Call once at startup. Bindings are scoped to the editor’s key context, so they don’t shadow the host’s shortcuts.
find_in_source
Case-insensitive occurrences of query in content, as source byte ranges — the match list a find bar feeds to EditorState::set_search. Unicode-aware (comparison happens on lowercased text through an index map back to original byte offsets). An empty query matches nothing.
inline_math_sources
The LaTeX sources of every inline $…$ formula in content (the inner LaTeX, no $ delimiters), so a host can pre-render them into the same math store the block provider reads. Skips lines inside fenced code blocks, where $…$ is literal.
math_sources
The LaTeX sources of every $$…$$ math block in content, so a host can pre-render them (the editor’s math provider then finds the ready bitmap).
mermaid_sources
The diagram sources of every ```mermaid block in content, so a host can pre-render them (the editor’s mermaid provider then finds the ready bitmap).
paint_doc_icon
Paint a flat, line-art document glyph (a page with a folded top-right corner + two text lines) in color, the chip’s file icon. Drawn with strokes — not a font emoji — so it reads flat and on-theme at the text’s size. Public so a host’s read-only view can draw the identical icon on its own file chips (cross-view parity).

Type Aliases§

ClipboardWriter
Host-supplied clipboard writer for Copy/Cut — receives the markdown text the editor would put on the clipboard, so a host can add flavors gpui’s clipboard can’t (e.g. rendered HTML beside the plain string). See EditorState::set_clipboard_writer.
PropertyIconFn
Maps a property key to an icon asset path the host serves, or None for no icon. Host-provided so the crate makes no assumption about which assets exist.
ScrollCompensatorFn
Host hook for scroll anchoring: called from the measure pass when an ASYNC height change (a math/mermaid/image raster arriving) lands ABOVE the window’s viewport, with the height delta — the host shifts its scroll container’s offset by it so the content being read doesn’t jump.