Skip to main content

Crate editor

Crate editor 

Source
Expand description

A Notion-style block editor for gpui, over the markdown document model.

ⓘ
editor::init(cx);                       // once, at startup
let editor = cx.new(|cx| editor::Editor::new("# Title", cx));

markdown holds the document, its markdown wire form, and the painting — all of it testable without a window. What lives here is the half that needs one: focus, keys, the platform input handler, the mouse, undo, and the menus.

Modules§

keys
The keymap: every action the editor answers to, and the chords bound to it.

Structs§

Anchor
A range in the document, and which wash it paints.
AnchorId
The app’s key for a comment or a highlight. Opaque — nothing here looks inside one.
Chrome
Which of the editor’s own affordances are on.
Document
A markdown document as its editors share it.
DocumentEvent
A document changed under its editors. Every editor on it but the one that changed it takes the new snapshot.
Editor
Formatting
What a toolbar reads to light itself, in one call.
Handles
History
A document’s undo and redo stacks, shared by every editor on it.
ImageStore
Who owns the pictures a document points at.
Layout
What the editor lays the document out with.
Mention
One row of the mention menu.
PasteContext
The destination snapshot; the editor entity is being updated during the call.
Run
Where one editor’s run of edits left off: the kind of the last edit and where it left the caret, which decides whether the next edit joins that step or opens one of its own.
SlashAt
The block a SlashAction::Run row was picked for.
SlashRow
One row of the slash menu.
Step
The state a step restores, which is a whole moment rather than a diff.
TextSize
How far the chords move a document, in points — the unit a settings field is written in, so the two never need converting between.

Enums§

EditKind
What an edit did, so a run of the same kind can coalesce into one step instead of giving the document back a character at a time.
EditorEvent
What the editor tells its host about.
Mode
Which form the document is being edited in.
PasteContent
Content applied through normal editing and undo.
SlashAction
What picking a slash or block menu row does.
SlashItem
An item of the slash or block menu.
Source
A picture with no address of its own, and what the app is asked about.

Constants§

CONTEXT
DEFAULT_UNDO_LIMIT
How many steps a document keeps.
HIGHLIGHT_MARK
The custom mark ToggleHighlight toggles. It does nothing until the app registers a mark under this name with markdown::AppExt::set_marks.

Traits§

AppExt
Configuration carried by the application. Import as use editor::AppExt as _;.

Functions§

block_menu_defaults
The slash menu’s default blocks under “Turn into”, then Duplicate and Delete under “Block”.
init
Install the editor’s key bindings — bindings, bound.
quotes
Every quote a block can be put in, and what each is called. Pair with Editor::toggle_quote.
slash_defaults
The editor’s blocks as slash items, each under its glyph, the quotes and callouts behind one Quote group.
turns
Every block a block can be turned into, and what each is called — the vocabulary the slash menu and the block menu both offer, for an app building a menu of its own. Pair with Editor::set_block, which is what both of bezel’s own menus call.

Type Aliases§

MentionSource
The rows for what has been typed after the trigger, best first. Asked at paint.
PasteHandler
Called once before default clipboard handling. None keeps that behavior. The entity identifies the editor; do not read or update it during the call. Use the snapshot and cx.image_store() when calling ImageStore::keep.
SlashRun
What a SlashAction::Run row calls.
SourceRanges
Each anchor’s range in byte offsets into the markdown, None where the markdown has no place for an end.