Skip to content
gpdoc
Playground

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.

Terminal window
cargo add gpdoc-plugin-task-list

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.

Each task row receives the checked state, a checkbox that updates the document, and the editable task body.

task_rows(...)
└── div() Task row
├── task.checkbox Toggles the checked state and focuses the editor
└── task.content Editable 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.

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));

Register gpdoc_plugin_task_list::task_list() for the container. Register task_item() for the entries.

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()?;

A boolean on each taskItem, default false. Completion survives a document JSON round trip.

These commands take no arguments.

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)?;

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)?;

With the selection inside one task, move it up one level.

editor.run(gpdoc_plugin_task_list::Lift)?;

With nesting enabled, move the selected task under its previous sibling.

editor.run(gpdoc_plugin_task_list::Sink)?;
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.

task-list/src/lib.rs