From b8e7c5c51fc8f080a3870d1a4befe6a53916c25e Mon Sep 17 00:00:00 2001 From: Abdulleh Ghujeh Date: Thu, 31 Mar 2022 14:16:13 +0300 Subject: [PATCH] fix issue in negative line spacing with key arrow down when setting negative line spacing property with multiline text. using arrow down to move the main cursor will skip some line. Change-Id: Ia69d008203348776c860d5a8e7d1e5833a0e5f30 --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 44 ++++++++++++++++++++++ .../text/text-controller-impl-event-handler.cpp | 5 ++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 9d9567b..a01aac2 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -5857,6 +5857,50 @@ int UtcDaliTextEditorTextSizeNegativeLineSpacing(void) END_TEST; } +int UtcDaliTextEditorLineSpacingKeyArrowDown(void) +{ + ToolkitTestApplication application; + tet_infoline("UtcDaliTextEditorLineSpacingKeyArrowDown"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK(editor); + + application.GetScene().Add(editor); + + std::string cutText = ""; + std::string copiedText = ""; + + editor.SetProperty(TextEditor::Property::TEXT, "l1\nl2\nl3\n4"); + editor.SetProperty(TextEditor::Property::POINT_SIZE, 10.f); + editor.SetProperty(Actor::Property::SIZE, Vector2(300.f, 200.f)); + editor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + editor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + editor.SetProperty(TextEditor::Property::ENABLE_MARKUP, true); + editor.SetProperty(TextEditor::Property::LINE_SPACING, -15); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap on the text editor + TestGenerateTap(application, 1.0f, 1.0f); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Move to second line of the text. + application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(editor.GetProperty(DevelTextEditor::Property::PRIMARY_CURSOR_POSITION).Get(), 3, TEST_LOCATION); + + END_TEST; +} + int UtcDaliTextEditorNegativeLineSpacingWithEllipsis(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/text/text-controller-impl-event-handler.cpp b/dali-toolkit/internal/text/text-controller-impl-event-handler.cpp index cee6a88..1ed8c7f 100644 --- a/dali-toolkit/internal/text/text-controller-impl-event-handler.cpp +++ b/dali-toolkit/internal/text/text-controller-impl-event-handler.cpp @@ -379,14 +379,15 @@ void ControllerImplEventHandler::OnCursorKeyEvent(Controller::Impl& impl, const impl.GetCursorPosition(primaryCursorPosition, cursorInfo); // Get the line below. - const LineRun& line = *(visualModel->mLines.Begin() + lineIndex + 1u); + const LineRun& nextline = *(visualModel->mLines.Begin() + lineIndex + 1u); + const LineRun& currline = *(visualModel->mLines.Begin() + lineIndex); // Get last line index const LineIndex lastLineIndex = (visualModel->mLines.Size() > 0 ? visualModel->mLines.Size() - 1u : 0); const bool isLastLine = (lineIndex + 1u == lastLineIndex); // Get the next hit 'y' point. - const float hitPointY = cursorInfo.lineOffset + cursorInfo.lineHeight + 0.5f * GetLineHeight(line, isLastLine); + const float hitPointY = cursorInfo.lineOffset + GetLineHeight(currline, false) + 0.5f * GetLineHeight(nextline, isLastLine); // Use the cursor hook position 'x' and the next hit 'y' position to calculate the new cursor index. bool matchedCharacter = false; -- 2.7.4