textEditor issue


Hi Jules,

it looks like there is some issue in TextEditor.
If I change the text by typing and then right after programmatically clears it, it seems that this second change it not taken into account.

Any idea what I could check to understand what’s happening ?



Are you attaching the editor to a Value object? That might have the same effect…


no I don’t


Hmm… The only thing I can think of that might be happening is some kind of situation where the editor sets the Value object, and triggers an async update, in between which you set the value programmatically, and then the update arrives and replaces it.


any hints how I can avoid this issue then ?



Sorry, not really sure, because I don’t know what’s going on. If you want to do some digging and find out the mechanism that’s involved, I’m sure I can suggest something!


ok I have traced a bit the code so
textWasChangedByValue is called with the old text (the one before the manual setText)
So it’s indeed an issue with the asyncupdater.

I tried calling updateValueFromText() right before setText (textValue.getValue())
but maybe it’s textValue.getValueSource().cancelPendingUpdate() which should be called in TextEditor::setText

both looks like to work in my case but I don’t know much.
Hope it gives you some hints


bump :slight_smile:


Hmm. How about adding this line?

[code]void TextEditor::setText (const String& newText,
const bool sendTextChangeMessage)
const int newLength = newText.length();

if (newLength != getTotalNumChars() || getText() != newText)
    textValue = newText;

    const int oldCursorPos = caretPosition;
    const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();



It fixes the issue.


Great, thanks!