Selecting nodes: CTRL-A behaves different after CTRL-Z

The problem is that selected Parts can remain selected (i.e. Part.isSelected is true and it is in the Diagram.selection) even when the part no longer “exists” because of an undo of an insertion of a new selected Part.

Keeping the selection state independent of being in the diagram is convenient when using undo and redo, so that the user can keep track of what has been happening with selected parts. I suppose we could change the CommandHandler.selectAll command to make sure there aren’t any non-existing parts in the resulting Diagram.selection collection, but that would not avoid the situation that you described. Instead of using Ctrl-A, the user might shift-click or control-click to select one or more of the remaining parts. That would still leave the at-the-moment-not-in-the-diagram parts in the selection collection.

I’m not sure what you want in your Angular model when a selected part is deleted, at any given moment. Here’s one possibility:

          // update the Angular model when the Diagram.selection changes
          function updateSelection(e) {
            diagram.model.selectedNodeData = null;
            var it = diagram.selection.iterator;
            while (it.next()) {
              var selnode = it.value;
              // ignore a selected link or a deleted node
              if (selnode instanceof go.Node && selnode.data !== null) {
                diagram.model.selectedNodeData = selnode.data;
                break;
              }
            }
            scope.$apply();
          }

By the way, not directly related to this topic, but something you might want to know: ChangedSelection is not triggered - #2 by walter