Skip to content
gpdoc
Playground

List keyboard shortcuts

Handle Backspace, Delete, and Tab at list boundaries.

list_keymap() handles list-specific key presses around bullet, ordered, and task items. At the start of the first item, Backspace can lift it out of the list.

Terminal window
cargo add gpdoc-plugin-list-keymap

Add gpdoc-plugin-list-item and gpdoc-plugin-bullet-list to the Quickstart app to use the list shortcuts with bullet items.

use gpdoc::EditorConfig;
use gpdoc_plugin_paragraph::paragraph;
use gpdoc_plugin_list_item::list_item;
use gpdoc_plugin_bullet_list::bullet_list;
use gpdoc_plugin_list_keymap::list_keymap;
let config = EditorConfig::builder()
.plugin(paragraph())
.plugin(list_item())
.plugin(bullet_list())
.plugin(list_keymap())
.build()
.expect("configure editor");

Create a bullet list, place the caret at the beginning of its first item, and press Backspace. The editor lifts the item into a paragraph.

use gpdoc::{DocPos, Editor, Node, Selection};
let mut editor = Editor::from_document(&config, vec![Node::textblock("paragraph", "First item")])?;
editor.run(gpdoc_plugin_bullet_list::Toggle)?;
editor.select(Selection::caret(DocPos(3)))?;
editor.run(gpdoc_plugin_list_keymap::Backspace)?;
assert_eq!(editor.document().blocks()[0].kind, "paragraph");

gpdoc_plugin_list_keymap::list_keymap() takes no options. Register it alongside the list types you use. See Combine list plugins for an example with bullet, ordered, and task lists.

Each command requires a collapsed text selection.

At the beginning of the first item, lift the item one level. At the beginning of a later item, join its first paragraph to the preceding item’s final paragraph.

editor.run(gpdoc_plugin_list_keymap::Backspace)?;

At the end of an item, join its final paragraph to the following item’s first paragraph. Both sides of the boundary must be paragraphs.

editor.run(gpdoc_plugin_list_keymap::Delete)?;

At the start of a text block immediately after a list, move that block into the last list item if the schema accepts it.

editor.run(gpdoc_plugin_list_keymap::Tab)?;
Shortcut Command
Backspace or Mod + Backspace listBackspace
Delete or Mod + Delete listDelete
Tab listTab

list-keymap/src/lib.rs