From cf24b8abe44969c09f8cc0a69d4833c8681e5f52 Mon Sep 17 00:00:00 2001 From: S6066 Date: Fri, 3 Aug 2018 08:45:42 +0200 Subject: [PATCH] TextAreaWidget: Implement movement with Ctrl key (#176) * TextAreaWidget: Implement movement with Ctrl key * whoops, remove useless comments * Fixies --- ChangeLog.md | 1 + SDK/src/NDK/Widgets/TextAreaWidget.cpp | 55 ++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index f50db11c2..8514bbf26 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -129,6 +129,7 @@ Nazara Engine: - Fixed bug in ENet implementation causing legit reliable packets to be dropped on sequence number overflow - Fixed bug where index wouldn't be used in String::FindLast and String::FindWord - Physics 2D contact callbacks now include an arbiter allowing to query/set parameters about the collision +- Added movement with Ctrl in TextAreaWidget Nazara Development Kit: - Added ImageWidget (#139) diff --git a/SDK/src/NDK/Widgets/TextAreaWidget.cpp b/SDK/src/NDK/Widgets/TextAreaWidget.cpp index bf35c726e..334a78079 100644 --- a/SDK/src/NDK/Widgets/TextAreaWidget.cpp +++ b/SDK/src/NDK/Widgets/TextAreaWidget.cpp @@ -225,8 +225,12 @@ namespace Ndk if (ignoreDefaultAction) return true; - const auto& lineInfo = m_drawer.GetLine(m_cursorPositionEnd.y); - SetCursorPosition({ static_cast(m_drawer.GetLineGlyphCount(m_cursorPositionEnd.y)), m_cursorPositionEnd.y }); + std::size_t lineCount = m_drawer.GetLineCount(); + if (key.control && lineCount > 0) + SetCursorPosition({ static_cast(m_drawer.GetLineGlyphCount(lineCount - 1)), static_cast(lineCount - 1) }); + else + SetCursorPosition({ static_cast(m_drawer.GetLineGlyphCount(m_cursorPositionEnd.y)), m_cursorPositionEnd.y }); + return true; } @@ -238,7 +242,7 @@ namespace Ndk if (ignoreDefaultAction) return true; - SetCursorPosition({ 0U, m_cursorPositionEnd.y }); + SetCursorPosition({ 0U, key.control ? 0U : m_cursorPositionEnd.y }); return true; } @@ -252,6 +256,28 @@ namespace Ndk if (HasSelection()) SetCursorPosition(m_cursorPositionBegin); + else if (key.control) + { + std::size_t index = GetGlyphIndex(m_cursorPositionBegin); + + if (index == 0) + return true; + + std::size_t spaceIndex = m_text.FindLast(' ', index - 2); + std::size_t endlIndex = m_text.FindLast('\n', index - 1); + + if ((spaceIndex > endlIndex || endlIndex == Nz::String::npos) && spaceIndex != Nz::String::npos) + SetCursorPosition(spaceIndex + 1); + else if (endlIndex != Nz::String::npos) + { + if (index == endlIndex + 1) + SetCursorPosition(endlIndex); + else + SetCursorPosition(endlIndex + 1); + } + else + SetCursorPosition({ 0U, m_cursorPositionBegin.y }); + } else MoveCursor(-1); @@ -268,6 +294,29 @@ namespace Ndk if (HasSelection()) SetCursorPosition(m_cursorPositionEnd); + else if (key.control) + { + std::size_t index = GetGlyphIndex(m_cursorPositionEnd); + std::size_t spaceIndex = m_text.Find(' ', index); + std::size_t endlIndex = m_text.Find('\n', index); + + if (spaceIndex < endlIndex && spaceIndex != Nz::String::npos) + { + if (m_text.GetSize() > spaceIndex) + SetCursorPosition(spaceIndex + 1); + else + SetCursorPosition({ static_cast(m_drawer.GetLineGlyphCount(m_cursorPositionEnd.y)), m_cursorPositionEnd.y }); + } + else if (endlIndex != Nz::String::npos) + { + if (index == endlIndex) + SetCursorPosition(endlIndex + 1); + else + SetCursorPosition(endlIndex); + } + else + SetCursorPosition({ static_cast(m_drawer.GetLineGlyphCount(m_cursorPositionEnd.y)), m_cursorPositionEnd.y }); + } else MoveCursor(1);