From 2eca1d9b04a9da03fadb0192b0597942481e3fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ta=C5=84ski?= Date: Tue, 29 Jun 2021 17:26:56 +0200 Subject: [PATCH] [EGD-7047] Fixed navigation down through input texts Fixed navigation down through input texts while adding a new contact. --- module-gui/gui/widgets/TextLineCursor.cpp | 6 ++- .../test/test-catch-text/test-gui-Text.cpp | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/module-gui/gui/widgets/TextLineCursor.cpp b/module-gui/gui/widgets/TextLineCursor.cpp index e16a417d82482c61392f574c32f8d9d4ba8c934e..9424b9ce19c2f03b2b7989500a6b7ec9c0de1513 100644 --- a/module-gui/gui/widgets/TextLineCursor.cpp +++ b/module-gui/gui/widgets/TextLineCursor.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "TextLineCursor.hpp" @@ -220,6 +220,10 @@ namespace gui if (direction == NavigationDirection::DOWN) { + if (checkNextLineDocumentEnd(selectedLineNumber)) { + return TextCursor::Move::End; + } + handleDownNavigation(selectedLineNumber, selectedLineCursorPosition); debug_text_cursor("After move cursor: screen pos: %d block: %d pos: %d %s", diff --git a/module-gui/test/test-catch-text/test-gui-Text.cpp b/module-gui/test/test-catch-text/test-gui-Text.cpp index d3a8086cf1ad984d71ccf27bbfa60a314637c975..e3a6dcdb31e61f630350d3172e45db0deae877e5 100644 --- a/module-gui/test/test-catch-text/test-gui-Text.cpp +++ b/module-gui/test/test-catch-text/test-gui-Text.cpp @@ -18,6 +18,7 @@ #include #include "Font.hpp" #include "RichTextParser.hpp" +#include "TextFixedSize.hpp" TEST_CASE("Text ctor") { @@ -1330,3 +1331,41 @@ TEST_CASE("RichText newline and empty lines tests") REQUIRE((*text->lineGet(2)).getText(0) == ""); } } + +TEST_CASE("Navigating down between input texts") +{ + using namespace gui; + const InputEvent keyDown{{}, InputEvent::State::keyReleasedShort, KeyCode::KEY_DOWN}; + + mockup::fontManager(); + SECTION("Empty texts") + { + auto layout = VBox(nullptr, 0, 0, 100, 200); + [[maybe_unused]] auto text1 = new TextFixedSize(&layout, 0, 0, 100, 150); + [[maybe_unused]] auto text2 = new TextFixedSize(&layout, 0, 150, 100, 50); + layout.setFocus(true); + + REQUIRE(layout.getFocusItemIndex() == 0); + + layout.onInput(keyDown); + REQUIRE(layout.getFocusItemIndex() == 1); + } + + SECTION("Non-empty texts and no new line at the end [EGD-7047]") + { + constexpr auto testString = "Test String"; + + auto layout = VBox(nullptr, 0, 0, 100, 200); + auto text1 = new TextFixedSize(&layout, 0, 0, 100, 150); + text1->addText(TextBlock(testString, Font(27).raw(), TextBlock::End::None)); + text1->setCursorStartPosition(CursorStartPosition::DocumentBegin); + + [[maybe_unused]] auto text2 = new TextFixedSize(&layout, 0, 150, 100, 50); + layout.setFocus(true); + + REQUIRE(layout.getFocusItemIndex() == 0); + + layout.onInput(keyDown); + REQUIRE(layout.getFocusItemIndex() == 1); + } +}