From 79338c71772b2c4734acaff2e4f63f83c2ae7e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 10 Nov 2017 13:38:06 +0100 Subject: [PATCH] Sdk/TextAreaWidget: Fix issues when deleting characeters --- SDK/src/NDK/Widgets/TextAreaWidget.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SDK/src/NDK/Widgets/TextAreaWidget.cpp b/SDK/src/NDK/Widgets/TextAreaWidget.cpp index 2343f3aae..0d316a452 100644 --- a/SDK/src/NDK/Widgets/TextAreaWidget.cpp +++ b/SDK/src/NDK/Widgets/TextAreaWidget.cpp @@ -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);