Skip to content
gpdoc
Playground

Details

Wrap blocks in a disclosure with an editable summary.

details() groups a summary and a body that the editor view can expand or collapse. Use it for notes readers can open when they need them.

Terminal window
cargo add gpdoc-plugin-details

Register details() to install the disclosure node and its two child types. The summary holds text. The body holds one or more blocks.

Register the disclosure and its summary view alongside paragraphs for the body. Use this configuration in the Quickstart editor.

use gpdoc::{EditorConfig, PluginViewExt, ViewPlugin};
use gpdoc_plugin_paragraph::paragraph;
use gpdoc_plugin_details::{DetailsSummary, details, disclosure};
let config = EditorConfig::builder()
.plugin(paragraph())
.plugin(details().with_view(header_view))
.build()
.expect("configure editor");
fn header_view() -> ViewPlugin {
disclosure(DetailsSummary::render)
}

Run gpdoc_plugin_details::Set on a paragraph, then type a summary. Click the arrow beside the summary to open the body.

The plugin supplies the fold trigger and editable summary. It manages the body and keyboard navigation.

disclosure(...)
└── div() Summary row
├── header.trigger Toggles the body on click
└── header.content Editable summary

Replace header_view in the example above.

use gpui::{div, prelude::*};
fn header_view() -> ViewPlugin {
disclosure(|header, _, _| {
div().flex()
.child(header.trigger.child(if header.open { "−" } else { "+" }))
.child(header.content)
})
}

Click the plus sign to open the body. The trigger now displays a minus sign.

To wrap the body as well, call .wrap_node("detailsContent", ...) on the view returned by disclosure and place the supplied editable content inside your wrapper.

use gpdoc::{Editor, Node};
let mut editor = Editor::from_document(&config, vec![Node::textblock("paragraph", "The full change log.")])?;
editor.run(gpdoc_plugin_details::Set)?;
editor.insert_text("Release details")?;
let summary = Node::textblock("detailsSummary", "Release details");
assert!(editor.document().iter_nodes().any(|(_, node)| *node == summary));

With details(), each editor view owns the expanded state. To save that state in the document, register details_with_persistence(true). This adds the boolean node attribute open, which defaults to false.

use gpdoc::EditorConfig;
use gpdoc_plugin_details::details_with_persistence;
let config = EditorConfig::builder()
.plugin(paragraph())
.plugin(details_with_persistence(true))
.build()?;

Wrap selected sibling blocks when the body accepts them and their parent permits a disclosure. The editor moves the caret to the new, empty summary so the next text you type becomes its label.

editor.run(gpdoc_plugin_details::Set)?;

With a text selection wholly inside one disclosure, convert its summary to the parent’s default block type and place the body blocks after it. The caret returns to the start of the former summary.

editor.run(gpdoc_plugin_details::Unset)?;

details/src/lib.rs