Skip to content
gpdoc
Playground

Placeholder

Show a writing hint in an empty text block.

Click the empty paragraph and type an update. Delete what you typed to see the hint again.

Terminal window
cargo add gpdoc-plugin-placeholder
use gpdoc_plugin_placeholder::{placeholder, paint_placeholder};
use gpdoc_plugin_paragraph::paragraph;
let config = gpdoc::EditorConfig::builder()
.plugin(paragraph())
.plugin(placeholder("Write an update…").with_view(paint_placeholder))
.build()
.expect("configure editor");

Pass your own painter to .with_view(...) to change the appearance. It receives a PlaceholderHint with the block position, first-line bounds, and first line of the hint text. Call DecorationFrame::paint_text to use the current editor font and line height.

Place the caret in an empty top-level paragraph to see the hint. Typing the first character hides it. The view paints the hint without adding text to the document. To try it, press Enter at the end of a paragraph in the quickstart editor.

By default the hint appears only in the block containing the selection anchor. To include all empty blocks, set current_only = false on the value returned by placeholder(text). Set include_children = true to include nested empty blocks before registration.

placeholder/src/lib.rs