Fix bug in ui::Entry::m_caret, after changing the widget's text we've to adjust the caret

This is to avoid "out of range" situations, where the caret is outdated
and doesn't correspond to the new widget's text length.
This commit is contained in:
David Capello 2013-03-30 00:35:25 -03:00
parent 1d6be62ae7
commit fe6209ed52
2 changed files with 12 additions and 1 deletions

View File

@ -395,6 +395,14 @@ void Entry::onPaint(PaintEvent& ev)
getTheme()->paintEntry(ev);
}
void Entry::onSetText()
{
Widget::onSetText();
if (m_caret >= 0 && (size_t)m_caret > getTextSize())
m_caret = (int)getTextSize();
}
void Entry::onEntryChange()
{
EntryChange();
@ -450,8 +458,10 @@ void Entry::executeCmd(EntryCmd::Type cmd, int ascii, bool shift_pressed)
}
// put the character
if (text.size() < m_maxsize)
if (text.size() < m_maxsize) {
ASSERT((size_t)m_caret <= text.size());
text.insert(m_caret++, 1, ascii);
}
m_select = -1;
break;

View File

@ -47,6 +47,7 @@ namespace ui {
bool onProcessMessage(Message* msg) OVERRIDE;
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
void onPaint(PaintEvent& ev) OVERRIDE;
void onSetText() OVERRIDE;
// New Events
virtual void onEntryChange();