SDK/TextAreaWidget: Make character erasing work with cursor
Adds support for delete key
This commit is contained in:
parent
6c03803c5e
commit
85c5f4b48b
|
|
@ -115,6 +115,22 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
switch (key.code)
|
switch (key.code)
|
||||||
{
|
{
|
||||||
|
case Nz::Keyboard::Delete:
|
||||||
|
{
|
||||||
|
const Nz::String& text = m_drawer.GetText();
|
||||||
|
|
||||||
|
Nz::String newText;
|
||||||
|
if (m_cursorPosition > 0)
|
||||||
|
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorPosition) - 1));
|
||||||
|
|
||||||
|
if (m_cursorPosition < m_drawer.GetGlyphCount())
|
||||||
|
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorPosition + 1)));
|
||||||
|
|
||||||
|
m_drawer.SetText(newText);
|
||||||
|
m_textSprite->Update(m_drawer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case Nz::Keyboard::Left:
|
case Nz::Keyboard::Left:
|
||||||
if (m_cursorPosition > 0)
|
if (m_cursorPosition > 0)
|
||||||
m_cursorPosition--;
|
m_cursorPosition--;
|
||||||
|
|
@ -169,12 +185,22 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
case '\b':
|
case '\b':
|
||||||
{
|
{
|
||||||
Nz::String text = m_drawer.GetText();
|
const Nz::String& text = m_drawer.GetText();
|
||||||
|
|
||||||
text.Resize(-1, Nz::String::HandleUtf8);
|
Nz::String newText;
|
||||||
m_drawer.SetText(text);
|
if (m_cursorPosition > 1)
|
||||||
|
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorPosition - 1) - 1));
|
||||||
|
|
||||||
|
if (m_cursorPosition < m_drawer.GetGlyphCount())
|
||||||
|
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorPosition)));
|
||||||
|
|
||||||
|
m_drawer.SetText(newText);
|
||||||
m_textSprite->Update(m_drawer);
|
m_textSprite->Update(m_drawer);
|
||||||
|
|
||||||
|
if (m_cursorPosition > 0)
|
||||||
|
m_cursorPosition--;
|
||||||
|
|
||||||
|
RefreshCursor();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue