Task list
Create checklists with a saved checked state for each item.
task_list() registers the checklist container. task_item() registers the entries and stores each entry’s completion state in a boolean checked attribute.
Try it
Section titled “Try it”Install
Section titled “Install”cargo add gpdoc-plugin-task-listExample
Section titled “Example”Register the checklist container and its clickable task rows. Use this configuration in the Quickstart editor.
use gpdoc::{EditorConfig, PluginViewExt, ViewPlugin};use gpdoc_plugin_paragraph::paragraph;use gpdoc_plugin_task_list::{TaskRow, task_item, task_list, task_rows};
let config = EditorConfig::builder() .plugin(paragraph()) .plugin(task_item().with_view(task_view)) .plugin(task_list()) .build() .expect("configure editor");
fn task_view() -> ViewPlugin { task_rows(TaskRow::render)}Type [x] followed by a space to start a completed task. Click its checkbox to clear the checked state.
Compose a GPUI checklist
Section titled “Compose a GPUI checklist”Each task row receives the checked state, a checkbox that updates the document, and the editable task body.
Anatomy
Section titled “Anatomy”task_rows(...)└── div() Task row ├── task.checkbox Toggles the checked state and focuses the editor └── task.content Editable task bodyAssemble the checkbox and task body
Section titled “Assemble the checkbox and task body”Replace task_view in the example above.
use gpui::{div, prelude::*};
fn task_view() -> ViewPlugin { task_rows(|task, _, _| { let mark = if task.checked { "☑" } else { "☐" }; div().flex().child(task.checkbox.child(mark)).child(task.content) })}Put the glyph inside task.checkbox so clicking it toggles the task.
Create a checked task
Section titled “Create a checked task”use gpdoc::{Editor, Node, Value};
let mut editor = Editor::from_document(&config, vec![Node::textblock("paragraph", "")])?;editor.insert_text("[x] ")?;editor.insert_text("Write the release notes")?;
let (_, item) = editor.document().iter_nodes().find(|(_, node)| { node.kind == "taskItem"}).unwrap();assert_eq!(item.attrs["checked"], Value::Bool(true));Settings
Section titled “Settings”Register gpdoc_plugin_task_list::task_list() for the container. Register task_item() for the entries.
nested
Section titled “nested”Defaults to false. To allow subtasks, register task_item_with_nesting(nested: bool) in place of task_item(). This enables the sinkTaskItem command.
use gpdoc::EditorConfig;use gpdoc_plugin_task_list::task_item_with_nesting;
let config = EditorConfig::builder() .plugin(paragraph()) .plugin(task_item_with_nesting(true)) .plugin(task_list()) .build()?;checked
Section titled “checked”A boolean on each taskItem, default false. Completion survives a document JSON round trip.
Commands
Section titled “Commands”These commands take no arguments.
toggleTaskList
Section titled “toggleTaskList”Wrap selected paragraphs in a checklist, lift selected items from a checklist, or convert a compatible list to a checklist.
editor.run(gpdoc_plugin_task_list::Toggle)?;splitTaskItem
Section titled “splitTaskItem”Split at a text caret or replace the selected text within a task paragraph with an item boundary. The new item starts unchecked. An item containing only an empty paragraph lifts one level.
editor.run(gpdoc_plugin_task_list::Split)?;liftTaskItem
Section titled “liftTaskItem”With the selection inside one task, move it up one level.
editor.run(gpdoc_plugin_task_list::Lift)?;sinkTaskItem
Section titled “sinkTaskItem”With nesting enabled, move the selected task under its previous sibling.
editor.run(gpdoc_plugin_task_list::Sink)?;Keyboard shortcuts
Section titled “Keyboard shortcuts”| Shortcut | Command |
|---|---|
| Mod + Shift + 9 | toggleTaskList |
| Enter | splitTaskItem |
| Shift + Tab | liftTaskItem |
| Tab (nesting enabled) | sinkTaskItem |
At the start of a paragraph, type [ ] followed by a space for an unchecked task or [x] followed by a space for a checked one. The input rule consumes the marker.