Skip to content
gpdoc
Playground

Plugins

Browse gpdoc plugins by feature and find install commands and Rust examples.

Choose a plugin to see how to register it in the Quickstart editor. For plugins with UI components, the Compose section shows how to assemble their parts in your own view.

Formatting

Blocks

Lists and tables

Media and math

Selection

Writing tools

Files and Markdown

Collaboration

Register plugins before opening a document. Use gpdoc::EditorConfig::builder() to register plugins, then pass the configuration to an editor constructor. A plugin can define a node, a mark, a command, a shortcut, or a rule that runs as you type. The engine provides the doc and text types. Add Paragraph for the default text block.

If a snippet uses an existing editor, register the required plugins in an EditorConfig and place the snippet inside main after creating the editor. For examples that call a codec or collaboration API, use Result<(), Box<dyn std::error::Error>> as the return type of main.

In the Quickstart app, add Placeholder and Gap cursor. Register each plugin to use its default GPUI behavior.

Terminal window
cargo add gpdoc-plugin-placeholder gpdoc-plugin-gap-cursor
use gpdoc_plugin_gap_cursor::gap_cursor;
use gpdoc_plugin_paragraph::paragraph;
use gpdoc_plugin_placeholder::placeholder;
let config = gpdoc::EditorConfig::builder()
.plugin(paragraph())
.plugin(placeholder("Write an update…"))
.plugin(gap_cursor())
.build()?;

An empty paragraph shows the writing hint. In a document with adjacent closed blocks, click their boundary to place the gap cursor. To change how a plugin looks, define a view in your application and register it with .with_view(...).

For an editable block, wrap the paragraph content in a GPUI element. For a menu, compose a slash command picker with your own panel and rows. To put an action above the caret, add a button to a link popover.

Format a selection

Pick a phrase and toggle bold or italic on it.

Document
Give the release notes a little emphasis.

Loading example…

From your Quickstart project, add the two formatting plugins.

Terminal window
cargo add gpdoc-plugin-bold gpdoc-plugin-italic

Replace src/main.rs with this example and run cargo run. The program prints the marks attached to release notes.

use gpdoc::{DocPos, Editor, EditorConfig, Error, Node, Selection};
use gpdoc_plugin_bold::bold;
use gpdoc_plugin_italic::italic;
use gpdoc_plugin_paragraph::paragraph;
fn main() -> Result<(), Error> {
let config = EditorConfig::builder()
.plugin(paragraph())
.plugin(bold())
.plugin(italic())
.build()?;
let mut editor = Editor::from_document(&config, vec![Node::textblock(
"paragraph",
"Give the release notes a little emphasis.",
)])?;
editor.select(Selection::Text {
anchor: DocPos(10),
head: DocPos(23),
})?;
editor.run(gpdoc_plugin_bold::Toggle)?;
editor.run(gpdoc_plugin_italic::Toggle)?;
let (_, phrase) = editor
.document()
.iter_nodes()
.find(|(_, node)| node.projected_text() == "release notes")
.expect("the selected phrase has its own text node");
for mark in phrase.marks() {
println!("{}", mark.kind);
}
Ok(())
}
bold
italic

Pass a command value exported by the plugin to editor.run(command). Its Rust type specifies the arguments.

Result from editor.run Meaning
Ok(CommandOutcome::Applied(change)) The editor applied the command’s transaction and returned an AppliedChange.
Ok(CommandOutcome::NotApplicable) The command declined the current selection or arguments. The editor stays as it was.
Ok(CommandOutcome::Rejected) A transaction filter declined the final draft. The document and undo history are unchanged. GPUI consumes the shortcut.
Err(Error::UnknownCommand(name)) Register the plugin that handles this command type.
Other Err(error) Planning or applying the transaction failed. The error describes the cause.

When wiring a toolbar button, pass its command value to editor.can(command). It returns Ok(true) when the handler can plan a valid transaction in the current context. The editor discards that transaction. On click, run() plans again, runs append hooks, and lets filters accept or reject the final draft. A button can therefore be enabled and its command still return Rejected.

The editor has built-in local undo and redo. Use editor.undo() and editor.redo() to move through the history.

Create your first plugin to build and test a caption block. Then choose a guide for the feature you want to add.

To add Guide
A document type, a formatting mark, or a validated field Nodes, marks, and attributes
An editing action with a keyboard binding Commands and shortcuts
A value that an editor remembers between commands Transactions and plugin state
A conversion triggered by typing or pasting Input and paste rules
A native renderer for an editable block Render a plugin in GPUI

For signatures and hook behavior, see the Plugin API reference.