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.
Try it
Section titled “Try it”Install
Section titled “Install”cargo add gpdoc-plugin-detailsRegister details() to install the disclosure node and its two child types. The summary holds text. The body holds one or more blocks.
Example
Section titled “Example”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.
Compose a GPUI disclosure
Section titled “Compose a GPUI disclosure”The plugin supplies the fold trigger and editable summary. It manages the body and keyboard navigation.
Anatomy
Section titled “Anatomy”disclosure(...)└── div() Summary row ├── header.trigger Toggles the body on click └── header.content Editable summaryAssemble the disclosure header
Section titled “Assemble the disclosure header”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.
Wrap a paragraph and give it a summary
Section titled “Wrap a paragraph and give it a summary”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));Settings
Section titled “Settings”details_with_persistence
Section titled “details_with_persistence”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()?;Commands
Section titled “Commands”setDetails
Section titled “setDetails”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)?;unsetDetails
Section titled “unsetDetails”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)?;