Skip to main content

keypress-on-todo

Description

Fires when a task is in focus at the time of using key navigation

Usage

"keypress-on-todo": ({
code: string,
event: KeyboardEvent
}) => void;

Parameters

The callback of the keypress-on-todo event can take an object with the following parameters:

  • code - (required) the code of the pressed key or a combination of the pressed keys in the lower case. The full lists of keyboard shortcuts and their codes are given below
  • event - (required) a native event object
info

To handle the inner events, you can use the Event Bus methods

Example

const { ToDo, Toolbar } = todo;
const {tasks, projects, users} = getData();

const list = new ToDo("#root", {
tasks,
projects,
users
});

const toolbar = new Toolbar("#toolbar", {
api: list.api,
});

// subscribe to the "keypress-on-todo" event
list.api.on("keypress-on-todo", ({code, event}) => {
console.log("The", code, "key is pressed");
});

Keyboard shortcuts

There are two groups of keyboard shortcuts:

1. Keyboard shortcuts in the default mode, i.e. when the editing mode of a task is not activated

Keyboard shortcutKey codeDescription
EscapeescapeCloses the menu if it is opened for the task when the key is pressed. Pressing again will close the editor, reset filtering, and collapse search results in the Toolbar
tip

The key codes described below are not available if focus is set on the Search bar of the Toolbar.

Keyboard shortcutKey codeDescription
EnterenterCreates a new task on the same level as the selected one, moves selection to the created task and opens the editor
SpacespaceMarks a task as complete or incomplete depending on its initial state
Delete/
Backspace
delete/
backspace
Removes the selected task by the following logic:
- after removing a child task, moves the selection down/up until it reaches the parent task
- after removing a parent task, moves the selection down to the next parent task if it's exist; otherwise, moves the selection up to the previous parent task
ArrowUparrowupMoves the selection up to the previous task
ArrowDownarrowdownMoves the selection down to the next task
ArrowRightarrowrightExpands the collapsed parent task
ArrowLeftarrowleftCollapses the expanded parent task. If the task is already collapsed or does not have child tasks, moves selection to the parent task
Ctrl+ArrowUpctrl+arrowupMoves the selected task up within the same level
Ctrl+ArrowDownctrl+arrowdownMoves the selected task down within the same level
TabtabDemotes the nesting level of the task to one lower level
Shift+Tabshift+tabPromotes the nesting level of the task to one higher level
Ctrl(Cmd)+Enterctrl+enterOpens the editor of the selected task
Ctrl(Cmd)+Dctrl+dDuplicates the selected task at the same level
Ctrl(Cmd)+Cctrl+cCopies the selected task into the clipboard, including all child tasks
Ctrl(Cmd)+Vctrl+vPastes the copied tasks to the same level as the currently selected task. It is possible to paste a copied task to any level, the structure of the copied task is saved

2. Keyboard shortcuts in the editing mode

Keyboard shortcutKey codeDescription
EscapeescapeCloses the editor without saving any changes you've made
EnterenterCloses the editor and saves the changes
Shift+Entershift+enterCreates a new paragraph