mirror of
https://github.com/aseprite/aseprite.git
synced 2024-11-20 14:21:45 +00:00
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:
parent
1d6be62ae7
commit
fe6209ed52
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user