# 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

[Try the details editor example](https://gpdoc.dev/docs/plugins/structure/details/#details-example)

## Install

```sh
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.

## Example

Register the disclosure and its summary view alongside paragraphs for the body. Use this configuration in the [Quickstart editor](/docs/quickstart/#configure-the-editor).

```rust
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

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

### Anatomy

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

### Assemble the disclosure header

Replace `header_view` in the example above.

```rust
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

```rust
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

### `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`.

```rust
use gpdoc::EditorConfig;
use gpdoc_plugin_details::details_with_persistence;


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

## Commands

### `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.

```rust
editor.run(gpdoc_plugin_details::Set)?;
```

### `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.

```rust
editor.run(gpdoc_plugin_details::Unset)?;
```

## Source code

[details/src/lib.rs](/source/plugins/details/src/lib.rs.txt)