Link connected objects from diagram giving wrong count on delete

I am using DiagramListener for deleting selected objects from diagram “SelectionDeleted”, now when i create two nodes connect them with link and try to select one node and delete, the e.subject.count inside SelectionDeleted is giving 2 where i just deleted one node.

var selectionDeleteHandler = function (diagram) {
diagram.addDiagramListener(“SelectionDeleted”, selectionDelete);
};

var selectionDelete = function (e) {
console.log(“Selection Deleted”, e.subject);
};

If I understand the situation, that sounds like the correct behavior. Two Parts are being deleted: a Node and a Link, because the default policy is to delete connected Links rather than leave them dangling. Naturally the listener may want to know about all of the Parts that were deleted.

Did you want to set CommandHandler | GoJS API to false?

I do also want to remove the link too,
For multi select I’m using e.subject.each inside selectionDelete, is there a way where maybe i could only be able to record deleted nodes, maybe something like subject.eachNode

Sure, as you are iterating over the e.subject collection, check whether the part is an instance of go.Node.

Thanks walter,

I managed to do so by comparing type.name and it worked!