As I understood diagram.commandHandler.editTextBlock(); shouldn’t be wrapped in a transaction.
In case I rename the node in the same transaction the text editor is not positioned correctly.
function newChildNode() {
if (diagram.model.selectedNodeData) {
const selectedNode: GoCanvasNode = diagram.selection.first();
if (selectedNode instanceof go.Node) {
diagram.startTransaction("Create new child node");
let newNode = { Id: temporaryNodeKey(), Name: "new node"};
diagram.model.addNodeData(newNode);
let newLink = { toNode: selectedNode.data.Id, fromNode: newNode.Id};
diagram.model.addLinkData(newLink);
editTextOnNewNode(newNode);
diagram.commitTransaction("Create new child node");
}
}
}
That is correct: CommandHandler.editTextBlock just starts the TextEditingTool, which conducts its own transaction when the user finishes editing.
Adding the “AnimationFinished” DiagramEvent listener after the previous transaction has finished might be too late. Register the listener before the previous transaction starts.
Ah, that seems to be a layout animation bug that has already been fixed in 1.7 beta.
What I tried was a simple modification to the State Chart sample. I added this function as a listener:
function startEditing(e) {
e.diagram.removeDiagramListener("AnimationFinished", startEditing);
e.diagram.commandHandler.editTextBlock();
}
And then I set it up in addNodeAndLink:
function addNodeAndLink(e, obj) {
var adornment = obj.part;
var diagram = e.diagram;
diagram.addDiagramListener("AnimationFinished", startEditing);
diagram.startTransaction("Add State");
. . .
Oh, I also set Diagram.layout to an instance of TreeLayout.
So when selecting a node and then clicking on the “+” Button to call addNodeAndLink, results in a new node and link being added, a regular layout animation, and then the start of editing the TextBlock:
This is in 1.7; I do not know why there is no “AnimationFinished” DiagramEvent in 1.6. But clearly it works in 1.7.