Skip to content

Commit

Permalink
Add open siblings command
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskerr committed Apr 4, 2024
1 parent fd6a30a commit 736cf98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/react-arborist/src/commands/default-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,17 @@ export function toggle(tree: Tree) {
node.isOpen ? tree.close(node.id) : tree.open(node.id);
}
}

export function openSiblings(tree: Tree) {
const node = tree.focusedNode;
if (!node) return;
const parent = node.parent;
if (!parent) return;

for (let sibling of parent.object.children!) {
if (!sibling.isLeaf) {
node.isOpen ? tree.close(sibling.id) : tree.open(sibling.id);
}
}
tree.scrollTo(node.rowIndex);
}
3 changes: 3 additions & 0 deletions modules/react-arborist/src/shortcuts/default-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ export const defaultShortcuts: ShortcutAttrs[] = [
{ key: " ", command: "select", when: "isLeaf" },
{ key: "Meta+a", command: "selectAll" },
{ key: "Control+a", command: "selectAll" },

/* Opening */
{ key: "*", command: "openSiblings" },
];

0 comments on commit 736cf98

Please sign in to comment.