~aleteoryx/muditaos

2eca1d9b04a9da03fadb0192b0597942481e3fef — Piotr Tański 4 years ago 3005b04
[EGD-7047] Fixed navigation down through input texts

Fixed navigation down through input texts while adding a new contact.
M module-gui/gui/widgets/TextLineCursor.cpp => module-gui/gui/widgets/TextLineCursor.cpp +5 -1
@@ 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",

M module-gui/test/test-catch-text/test-gui-Text.cpp => module-gui/test/test-catch-text/test-gui-Text.cpp +39 -0
@@ 18,6 18,7 @@
#include <RawFont.hpp>
#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);
    }
}