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.
Try it
Section titled “Try it”Install
Section titled “Install”cargo add gpdoc-plugin-list-keymapExample
Section titled “Example”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.
Lift the first item with Backspace
Section titled “Lift the first item with Backspace”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");Settings
Section titled “Settings”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.
Commands
Section titled “Commands”Each command requires a collapsed text selection.
listBackspace
Section titled “listBackspace”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)?;listDelete
Section titled “listDelete”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)?;listTab
Section titled “listTab”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)?;Keyboard shortcuts
Section titled “Keyboard shortcuts”| Shortcut | Command |
|---|---|
| Backspace or Mod + Backspace | listBackspace |
| Delete or Mod + Delete | listDelete |
| Tab | listTab |