TextEditor::clear() not working as expected

I’m trying to clear a TextEditor box after I put some text in it, similar to the following.

myBox.setText (juce::String ("abcde"));
...
myBox.clear();

However, clear() doesn’t delete the text and instead leaves it there. I’m currently using a workaround by calling setText again with a string that has a white space, which would visually clear the TextEditor.

myBox.setText (juce::String (" "));

I’m fairly new to Juce, so am I doing something wrong here?

I’m having the same issue. However, calling repaint(); on my top level component after TextEditor::clear() did work as expected.

1 Like

Bump – this is still an issue – needing to call repaint after clear manually

If you call clear()

    clearInternal (nullptr);
    checkLayout();
    undoManager.clearUndoHistory();

it will ultimately call

repaintText()

in remove(), via the clearInternal() call - whick looks like it would do the trick, but it does not.

It checks if the new text range is empty and exits if so - thus no “repaintText”.

Ending clear() it with a simple call to repaint () would be what you’d expect, instead of relying on assumptions about the 2 first calls, that fail to call repaint.

My 2 cents: keep bumping!

Thank you for reporting.

1 Like