Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ interface ICursorPosition<TDataType> {

| method | description |
|----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| getNode(path: number[]): ISlTreeNode | Find the node by using its path |
| getNode(path: number[]): ISlTreeNode | Find the node by using its path |
| traverse(cb: (node: ISlTreeNode, nodeModel: ISlTreeNodeModel, siblings: ISlTreeNodeModel[]) => boolean) | Helpful method to traverse all nodes. The traversing will be stopped if callback returns `false`. |
| updateNode(path: number[], patch: Partial<ISlTreeNodeModel>) | Update the node by using its path |
| select(path: number[], addToSelection = false) | Select the node by using its path | |
| getNodeEl(): HTMLElement | Get the node HTMLElement by using its path |
| updateNode(path: number[], patch: Partial<ISlTreeNodeModel>) | Update the node by using its path |
| select(path: number[], addToSelection = false) | Select the node by using its path | |
| getNodeEl(): HTMLElement | Get the node HTMLElement by using its path |
| getSelected(): ISlTreeNode[] | Get selected nodes |
| insert(position: ICursorPosition, nodeModel: ISlTreeNodeModel) | Insert nodes by the current cursor position. |
| remove(paths: number[][]) | Remove nodes by paths. For example `.remove([[0,1], [0,2]])`
| remove(paths: number[][]) | Remove nodes by paths. For example `.remove([[0,1], [0,2]])` |
| removeSelected() | Removes selected nodes (if any) |
| getFirstNode(): ISlTreeNode | Get the first node in the tree |
| getLastNode(): ISlTreeNode | Get the last node in the tree
| getNextNode(path: number[], filter?: (node: ISlTreeNode<TDataType>) => boolean): ISlTreeNode<TDataType>; | Get the next node. You can skip the next nodes by using `filter`
Expand Down
7 changes: 7 additions & 0 deletions demo/keyboardcontrol.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ <h2> Sl-vue-tree - Press Up and Down to move selection, Space and Enter to expan
const keyCode = event.code;
const slVueTree = this.$refs.slVueTree;

if(slVueTree.selectionSize > 0){
if (keyCode === 'Delete') {
slVueTree.removeSelected();
}
}

if (slVueTree.selectionSize === 1) {
const selectedNode = slVueTree.getSelected()[0];
let nodeToSelect;
Expand All @@ -124,6 +130,7 @@ <h2> Sl-vue-tree - Press Up and Down to move selection, Space and Enter to expan
slVueTree.select(slVueTree.getLastNode().path);
}
}

}
})
</script>
Expand Down
1 change: 1 addition & 0 deletions src/sl-vue-tree.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ export default class SlVueTree<TDataType> extends Vue {
getNodeEl(path: number[]): HTMLElement;
select(path: number[], addToSelection?: boolean): ISlTreeNode<TDataType>;
remove(paths: number[][]): void;
removeSelected(): void;
insert(cursorPosition: ICursorPosition<TDataType>, nodeModel:ISlTreeNodeModel<TDataType>): void;
}
9 changes: 9 additions & 0 deletions src/sl-vue-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,15 @@ export default {
this.emitInput(newNodes);
},

removeSelected() {
const selectedNodesPaths = [];
this.traverse((node) => {
if (node.isSelected) selectedNodesPaths.push(node.path);
});

this.remove(selectedNodesPaths);
},

insertModels(cursorPosition, nodeModels, newNodes) {
const destNode = cursorPosition.node;
const destSiblings = this.getNodeSiblings(newNodes, destNode.path);
Expand Down