How do I assign custom key bindings for the textBlock, like
I want to submit the text block on pressing Enter, currently on outside click of node submits the text,
(Enter goes into new line),
My requirement: On press Enter text should submit and Shift+Enter should go for new line
The built-in text editor is defined in extensions/TextEditor.js
or extensionsTS/TextEditor.ts
. Copy the file into your project and modify how it handles the “keydown” event:
textarea.addEventListener('keydown', function(e) {
// . . .
if (key === "Enter") {
if (!e.shiftKey || tool.textBlock.isMultiline === false) e.preventDefault();
if (!e.shiftKey) tool.acceptText(go.TextEditingTool.Tab);
// . . .
Make sure your custom text editor code is included in your project, and replace the standard text editor in your diagram:
$(go.Diagram, . . .,
{
"textEditingTool.defaultTextEditor": window.TextEditor,
. . .
OR the equivalent code:
myDiagram.toolManager.textEditingTool.defaultTextEditor = window.TextEditor;