Closing TextBlock editing programmatically

Once I have edited a TextBlock, I want to be able to accept the new text and close the editor programmatically, rather than by clicking somewhere else in the diagram. A bit like the converse of Diagram.commandHandler.editTextBlock(). I have tried Diagram.commandHandler.stopComamnd(): it closes the editor, but loses the new text. How can I achieve this?

Try calling TextEditingTool.acceptText.

Hi,
Which [quote=“walter, post:2, topic:6696”]
TextEditingTool.acceptText.
[/quote]
Should be called in this case?

I’m trying to call diagram.toolManager.textEditingTool.currentTextEditor.acceptText(go.TextEditingTool.Enter);
But it does nothing. Same with defaultTextEditor.

That should be an error because acceptText is defined on TextEditingTool, not on the HTML DOM Element interface.

Yes, you right it was diagram.toolManager.textEditingTool.currentTextEditor.textEditingTool

The problem in my case was that I was giving acceptText a wrong argument. When argument is LostFocus it accepts text as expected.

I have a custom dropdown custom text editor and in the change event listener I use acceptText() function to close automatically the text editor when I chose a value.

customText.addEventListener('change', (e) => {
			if (e.target.name === 'group1') {
				tool.acceptText();
				console.log("change");
			}
...

The console.log is called but the acceptText() do nothing.
What could be the problem ?
(I use GoJS 2)

The TextEditingTool.acceptText method requires an argument specifying the reason for the completion of the tool.
TextEditingTool | GoJS API

OK thank you, so is there a way to do what I want ?
When the dropdown custom editor text value change, the textBlock take this value and the editor close automaticaly ?

Try passing go.TextEditingTool.Tab as the argument.