Hi,
I recently noticed that our app’s strange behavior.
After manipulating diagram (ex. move node, delete node, etc), undo (press Ctrl-Z) does not work, but once more press Ctrl-Z, undo works correctly.
(i.e. to undo we need to press Ctrl-Z twice)
To see what happened, I wrote following code to see undoManager’s transaction history.
const histLen = diagram.undoManager.history.length;
console.log(`undoManager.history.length=${diagram.undoManager.history.length}`);
console.log(`undoManager.historyIndex=${diagram.undoManager.historyIndex}`);
for (let i=0; i<histLen; i++) {
const hist: go.Transaction = diagram.undoManager.history.get(i);
console.log(`[${i}] ${hist.name}`);
}
after doing following manipulation, I run above code.
then I get this.
[manipulation]
(1) move node
(2) move node
(3) delete node
(4) mode node
[result]
undoManager.history.length=10
undoManager.historyIndex=9
[0] load initial network
[1] merge data
[2] Move
[3] merge data
[4] Move
[5] merge data
[6] deleteSelection
[7] merge data
[8] Move
[9] merge data
Probably because of “merge data” transaction, we need to press Ctrl-Z twice.
[Q1] What is “merge data” transaction? and what (when) makes this insert into history list?
[Q2] Is there any way to suppress “merge data” transaction?
Our app uses GoJS-React. and I hold nodeDataArray and linkDataArray within React’s state (useState), and I supply these 2 states to ReactDiagram’s property like this.
when doing something, I call setNodeDataArray() or setLinkDataArray() to update node/link.
I guess this architecture is what’s causing this strange ‘merge data’ transaction…?
const [nodeDataArray, setNodeDataArray] = React.useState<INexNodeData[]>([]);
const [linkDataArray, setLinkDataArray] = React.useState<INexLinkData[]>([]);
...
return (
<ReactDiagram
divClassName="diagram-component"
initDiagram={initDiagram}
nodeDataArray={nodeDataArray}
linkDataArray={linkDataArray}
/>
);
Takuya.