Select all text when EditBox is in focus

samaursa

19-02-2011 20:15:17

I am trying to select all the text (for faster input) when a textbox can receive keyboard input. I have a callback setup for that and it is being called properly. This is what I have in the callback though:


void MainState::EditBoxSelected( MyGUI::WidgetPtr aSender, MyGUI::WidgetPtr aOld )
{
MyGUI::EditBox* lEdit = aSender->castType<MyGUI::EditBox>();

lEdit->setTextSelection(0, lEdit->getCaption().size() - 1);
}


The code is being called, but it is not selecting the current text of the EditBox. What am I doing wrong and how can I have the text in the EditBoxbe automatically selected when a user clicks on that EditBox to type something (that is, when a user clicks on the EditBox, the text is automatically selected and the user can then start over-writing the old text without removing the old text first)

Altren

19-02-2011 23:35:18

You select characters between two indexes, so it is not from 0 to (size - 1), but from 0 to size:lEdit->setTextSelection(0, lEdit->getTextLength());Also getCaption().size() is bigger than getTextLength() whenever you use colour in text. For caption "#00FF00Hello" getTextLength return 5 and getCaption().size() return 12. Selection ignore colour of course, so you need to select range from 0 to 5 for whole "#00FF00Hello" text.

samaursa

20-02-2011 01:03:48

Thanks Altren. That works on its own but does not work when the mouse clicks on the editbox. I think it is because MyGUI automatically unselects text when I click on a textbox. Is there any way to disable that behavior?