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.

Structs§

Anchor
A comment’s range in the document, and which wash it paints.
Chrome
Which of the editor’s own affordances are on.
CommentId
The app’s key for a thread. Opaque — nothing here looks inside one.
Editor
Formatting
What a toolbar reads to light itself, in one call.
History
ImageStore
Who owns the pictures a document points at.
Layout
What the editor lays the document out with.
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.
Source
A picture with no address of its own, and what the app is asked about.

Constants§

DEFAULT_UNDO_LIMIT
How many steps a document keeps.

Functions§

adjust_text_size
Move every open document by points, each staying inside the range against its own base.
init
Install the editor’s key bindings. Scoped to the editor’s own key context, so binding tab here does not make tab mean “indent” for the whole app.
reset_text_size
Give every document back to the size its app set it at.
set_image_store
editor::set_image_store(cx, my_store) — call once at boot. Without it a screenshot cannot be pasted at all: there is nowhere to put the bytes, and a document holds a URL.
set_layout
editor::set_layout(cx, my_layout) — call once at boot.
set_text_size
editor::set_text_size(cx, my_steps) — call once at boot.
text_size_adjustment
What every document is currently set away from its base by, in points.
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.