Trim spaces in defaultTextEditor

Hi,

I’m trying to do a rather simple thing but I can’t see where I should do it.

A user is editing text using the default text editor. I need to trim() spaces on this text before it gets anywhere.

So far I’ve tried changing value diagram.toolManager.textEditingTool.defaultTextEditor in onDeactivate callback, adding a value function to defaultTextEditor, adding event listeners for blur and keydown. And all of those seems to be too late because value is updated, but what being sent still contains old value with spaces.

Well, in version 1.7, which has been in beta for a long time and which will be released later this week, you can do:

        $(go.TextBlock,
          {
            editable: true,
            textEdited: function(tb, oldstr, newstr) {
              tb.text = newstr.trim();
            }
          },
          new go.Binding("text").makeTwoWay())

In any version you could implement a “TextEdited” DiagramEvent listener. For example in this Diagram initialization:

  $(go.Diagram, . . .,
        {    . . . ,
            "TextEdited": function(e) {
              var tb = e.subject;
              tb.text = tb.text.trim();
            }
        })

1.7 is great news:) Thank you!

Hello,

GoJS 1.7 has been released as the latest stable version.

https://www.nwoods.com/app/activate.aspx?sku=gojs

Simon