X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller-impl-event-handler.cpp;h=1ed8c7f1144dee4f9dbc6ac5af58cbfc1b791a62;hp=416f937eff12b95e33e29c20510ccdd2fcbfeb22;hb=6a219d0bbcfd016e24b5466d5fb1a666c92feae5;hpb=5196315c0dcb4ffe51650ebd5415d680be611f7e 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 416f937..1ed8c7f 100644 --- a/dali-toolkit/internal/text/text-controller-impl-event-handler.cpp +++ b/dali-toolkit/internal/text/text-controller-impl-event-handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -334,6 +334,8 @@ void ControllerImplEventHandler::OnCursorKeyEvent(Controller::Impl& impl, const const LineIndex lineIndex = visualModel->GetLineOfCharacter(characterIndex); const LineIndex previousLineIndex = (lineIndex > 0 ? lineIndex - 1u : lineIndex); + const LineIndex lastLineIndex = (visualModel->mLines.Size() > 0 ? visualModel->mLines.Size() - 1u : 0); + const bool isLastLine = (previousLineIndex == lastLineIndex); // Retrieve the cursor position info. CursorInfo cursorInfo; @@ -344,7 +346,7 @@ void ControllerImplEventHandler::OnCursorKeyEvent(Controller::Impl& impl, const const LineRun& line = *(visualModel->mLines.Begin() + previousLineIndex); // Get the next hit 'y' point. - const float hitPointY = cursorInfo.lineOffset - 0.5f * GetLineHeight(line); + const float hitPointY = cursorInfo.lineOffset - 0.5f * GetLineHeight(line, isLastLine); // Use the cursor hook position 'x' and the next hit 'y' position to calculate the new cursor index. bool matchedCharacter = false; @@ -377,10 +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); + 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; @@ -418,13 +425,23 @@ void ControllerImplEventHandler::OnCursorKeyEvent(Controller::Impl& impl, const if(cursorPositionDelta > 0 || eventData.mRightSelectionPosition > 0u) // Check the boundary { eventData.mRightSelectionPosition += cursorPositionDelta; + eventData.mPrimaryCursorPosition = eventData.mRightSelectionPosition; if(impl.mSelectableControlInterface != nullptr) { impl.mSelectableControlInterface->SelectionChanged(oldSelStart, oldSelEnd, eventData.mLeftSelectionPosition, eventData.mRightSelectionPosition); } } - selecting = true; + + if(impl.mSelectableControlInterface != nullptr && eventData.mLeftSelectionPosition == eventData.mRightSelectionPosition) + { + // If left selection position and right selection position are the same, the selection is canceled. + selecting = false; + } + else + { + selecting = true; + } } else if(eventData.mLeftSelectionPosition != eventData.mRightSelectionPosition) { @@ -454,6 +471,12 @@ void ControllerImplEventHandler::OnCursorKeyEvent(Controller::Impl& impl, const eventData.mDecorator->SetPopupActive(false); } } + else + { + // If no selection, set a normal cursor. + impl.ChangeState(EventData::EDITING); + eventData.mUpdateCursorPosition = true; + } } else { @@ -701,6 +724,7 @@ void ControllerImplEventHandler::OnSelectAllEvent(Controller::Impl& impl) eventData.mLeftSelectionPosition = 0u; eventData.mRightSelectionPosition = model->mLogicalModel->mText.Count(); + eventData.mPrimaryCursorPosition = eventData.mRightSelectionPosition; if(impl.mSelectableControlInterface != nullptr) { @@ -719,12 +743,11 @@ void ControllerImplEventHandler::OnSelectNoneEvent(Controller::Impl& impl) EventData& eventData = *impl.mEventData; if(eventData.mSelectionEnabled && eventData.mState == EventData::SELECTING) { - eventData.mPrimaryCursorPosition = 0u; - uint32_t oldStart = eventData.mLeftSelectionPosition; - uint32_t oldEnd = eventData.mRightSelectionPosition; + uint32_t oldStart = eventData.mLeftSelectionPosition; + uint32_t oldEnd = eventData.mRightSelectionPosition; eventData.mLeftSelectionPosition = eventData.mRightSelectionPosition = eventData.mPrimaryCursorPosition; - impl.ChangeState(EventData::INACTIVE); + impl.ChangeState(EventData::EDITING); eventData.mUpdateCursorPosition = true; eventData.mUpdateInputStyle = true; eventData.mScrollAfterUpdatePosition = true; @@ -759,6 +782,7 @@ void ControllerImplEventHandler::OnSelectRangeEvent(Controller::Impl& impl, cons impl.mEventData->mLeftSelectionPosition = start; impl.mEventData->mRightSelectionPosition = end; + impl.mEventData->mPrimaryCursorPosition = end; if(impl.mSelectableControlInterface != nullptr) {