textEditor issue


#1

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 ?

Thanks,


#2

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


#3

no I don’t


#4

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.


#5

any hints how I can avoid this issue then ?

Thanks,


#6

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!


#7

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


#8

bump :slight_smile:


#9

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();

[/code]


#10

It fixes the issue.


#11

Great, thanks!