diff --git a/modules/react-arborist/src/commands/default-commands.ts b/modules/react-arborist/src/commands/default-commands.ts index a121021..0833725 100644 --- a/modules/react-arborist/src/commands/default-commands.ts +++ b/modules/react-arborist/src/commands/default-commands.ts @@ -133,3 +133,19 @@ export function moveSelectionEnd(tree: Tree) { tree.selectContiguous(next.id); } } + +export function select(tree: Tree) { + const node = tree.focusedNode; + if (node) tree.select(node.id); +} + +export function selectAll(tree: Tree) { + tree.selectAll(); +} + +export function toggle(tree: Tree) { + const node = tree.focusedNode; + if (node) { + node.isOpen ? tree.close(node.id) : tree.open(node.id); + } +} diff --git a/modules/react-arborist/src/shortcuts/default-shortcuts.ts b/modules/react-arborist/src/shortcuts/default-shortcuts.ts index e4c6fcd..9254629 100644 --- a/modules/react-arborist/src/shortcuts/default-shortcuts.ts +++ b/modules/react-arborist/src/shortcuts/default-shortcuts.ts @@ -26,17 +26,8 @@ export const defaultShortcuts: ShortcutAttrs[] = [ /* Selection */ { key: "Shift+ArrowUp", command: "moveSelectionStart" }, { key: "Shift+ArrowDown", command: "moveSelectionEnd" }, - - /* Activation */ - // { key: "Meta+ArrowDown", command: "activate" }, - // { key: "ArrowLeft", command: "close", when: "isOpen" }, - // { key: "ArrowLeft", command: "focusParent", when: "isLeaf || isClosed" }, - // { key: "ArrowRight", command: "focusChildren" }, - // { key: "Meta+A", command: "selectAll" }, - // { key: "Control+A", command: "selectAll" }, - // { key: "a", command: "createLeaf" }, - // { key: "Shift+A", command: "createInternal" }, - // { key: "Home", command: "focusFirst" }, - // { key: "End", command: "focusLast" }, - // { key: "Enter", command: "" }, + { key: " ", command: "toggle", when: "isInternal" }, + { key: " ", command: "select", when: "isLeaf" }, + { key: "Meta+a", command: "selectAll" }, + { key: "Control+a", command: "selectAll" }, ];