fix selection issue in OnCursorKeyEvent 33/263333/2
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 31 Aug 2021 12:08:52 +0000 (21:08 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Fri, 3 Sep 2021 09:07:11 +0000 (18:07 +0900)
Solved the problem when selecting with Shift + Left, Right.

1. Deselect the left == right case.
Previously, the selection handle was drawn even though nothing was selected, which looked weird.

2. For SelectWholeText and SelectText, set PrimaryCursorPosition to RightSelectionPosition.
Selection processing in OnCursorKeyEvent is implemented assuming that the cursor position is RightSelectionPosition.

mPrimaryCursorPosition = mRightSelectionPosition;
This ensures the above behavior.

Change-Id: I1208e37c93e9941319bc1b88502632800129e4d8
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
dali-toolkit/internal/text/text-controller-impl-event-handler.cpp

index e298a5a..290c229 100644 (file)
@@ -418,13 +418,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 +464,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 +717,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,8 +736,8 @@ void ControllerImplEventHandler::OnSelectNoneEvent(Controller::Impl& impl)
     EventData& eventData = *impl.mEventData;
     if(eventData.mSelectionEnabled && eventData.mState == EventData::SELECTING)
     {
-      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::EDITING);
@@ -758,6 +775,7 @@ void ControllerImplEventHandler::OnSelectRangeEvent(Controller::Impl& impl, cons
 
       impl.mEventData->mLeftSelectionPosition  = start;
       impl.mEventData->mRightSelectionPosition = end;
+      impl.mEventData->mPrimaryCursorPosition  = end;
 
       if(impl.mSelectableControlInterface != nullptr)
       {