CommandHandler.selectAll

I am overwriting the selectAll method in CommandHandler. We have container (group?) nodes in our Diagram. When we select all - CTRL/CMD+A - we want to select all of the nodes, but not the children nodes of containers.

My original thought was - loop through all nodes in the diagram - and any with a parent should be unselected.

  selectAll(): void {
    if (!super.canSelectAll()) return;

    this.diagram?.nodes.each(node => {
      node.isSelected = !node.findTreeParentNode();
    });
  }

But all of my nodes are still selected. I am not sure if I am on the right track, or even using the correct items in the diagram to solve this problem. Any help here would be appreciated.

Try:

  selectAll(): void {
    this.diagram.selectCollection(this.diagram.nodes.filter(n => n.isTopLevel && n.canSelect()));
  }

Thank you, walter!

Actually, the command should not call the CommandHandler’s can… predicate. I have updated my code, above.

1 Like