Sdk/TextAreaWidget: Fix issues when deleting characeters

This commit is contained in:
Jérôme Leclercq 2017-11-10 13:38:06 +01:00
parent e3f21b7268
commit 79338c7177
1 changed files with 9 additions and 4 deletions

View File

@ -139,11 +139,15 @@ namespace Ndk
{
case Nz::Keyboard::Delete:
{
std::size_t textLength = m_text.GetLength();
if (m_cursorGlyph > textLength)
break;
Nz::String newText;
if (m_cursorGlyph > 0)
newText.Append(m_text.SubString(0, m_text.GetCharacterPosition(m_cursorGlyph) - 1));
if (m_cursorGlyph < m_text.GetLength())
if (m_cursorGlyph < textLength)
newText.Append(m_text.SubString(m_text.GetCharacterPosition(m_cursorGlyph + 1)));
SetText(newText);
@ -243,15 +247,16 @@ namespace Ndk
bool ignoreDefaultAction = false;
OnTextAreaKeyBackspace(this, &ignoreDefaultAction);
if (ignoreDefaultAction)
if (ignoreDefaultAction || m_cursorGlyph == 0)
break;
Nz::String newText;
if (m_cursorGlyph > 0)
if (m_cursorGlyph > 1)
newText.Append(m_text.SubString(0, m_text.GetCharacterPosition(m_cursorGlyph - 1) - 1));
if (m_cursorGlyph < m_text.GetLength())
newText.Append(m_text.SubString(m_text.GetCharacterPosition(m_cursorGlyph + 1)));
newText.Append(m_text.SubString(m_text.GetCharacterPosition(m_cursorGlyph)));
MoveCursor({-1, 0});
SetText(newText);