Overzealous adding of NodeData into treeView from palette

Continuing the discussion from Syncing treeview diagram with another diagram:

I also have a palette from which I can drag nodes and groups into my diagram. However, as soon as the object is dragged into myDiagram, a copy is created in the treeView. If I drag my mouse out and back in, another copy is created - and finally upon drop, a third copy is created.

I believe I should be checking to see if the current tool is draggingTool, but when I check, I seem to only be getting back ToolManager (line 378 in codepen)

Any thoughts on how to fix this?

Codepen example:

I think I’ve been able to fix duplication by commenting out the lines that splice e.newParam into nodeDataArray

   379 myTreeView.model.nodeDataArray.splice(e.newParam, 1);
   407 myDiagram.model.nodeDataArray.splice(e.newParam, 1);

but I’m not sure why this works. My understanding was that changes made to the nodeDataArray after the diagram has been rendered will not do anything unless the model is re-rendered from the nodeDataArray…

I’ll look into this tomorrow.

Thanks! Another thing - the console is screaming that there are many actions not within a transaction. However, when I try to wrap.

381 myTreeView.model.addNodeData(e.newValue);

385 if (treenode !== null) myTreeView.remove(treenode);

409 myDiagram.model.addNodeData(e.newValue);

413 if (node !== null) myDiagram.remove(node);

these lines into separate transactions for each, I still get “change not within a transaction” notices. Any thoughts?

Yes, I noticed that too. That’s because in one Diagram the “temporary” or “transient” side-effects are not being recorded in the UndoManager. But the Model Changed listener is modifying the other Diagram without also making sure those changes are not being recorded.

I’m still looking into this, as I can spare the cycles. This may take a while.

Try adding this statement at the beginning of each Model Changed listener:

      if (e.model.skipsUndoManager) return;

Worked like a charm. Thanks!