Fix wrong cursor position issues in difference horizontal alignment 51/215251/5
authorJiyun Yang <ji.yang@samsung.com>
Fri, 4 Oct 2019 06:50:41 +0000 (15:50 +0900)
committerjoogab yun <joogab.yun@samsung.com>
Mon, 7 Oct 2019 00:43:40 +0000 (00:43 +0000)
Previously, it does not align the last line with no character.
So the cursor position in the last empty line is not aligned.

Now it tests whether the alignment target indices includes end of the text
and the last line is generated but empty.

Change-Id: Icc525a94cdaca7e926c06a6615d6e319d7c55ae1
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
dali-toolkit/internal/text/cursor-helper-functions.cpp
dali-toolkit/internal/text/layouts/layout-engine.cpp
dali-toolkit/internal/text/text-controller.cpp

index f437b8d..19db7ae 100644 (file)
@@ -506,11 +506,8 @@ void GetCursorPosition( GetCursorPositionParameters& parameters,
     cursorInfo.primaryCursorHeight = cursorInfo.lineHeight;
 
     // Set the primary cursor's position.
-    cursorInfo.primaryPosition.x = 0.f;
+    cursorInfo.primaryPosition.x = ( LTR == line.direction ) ? newLine.alignmentOffset : parameters.visualModel->mControlSize.width - newLine.alignmentOffset;
     cursorInfo.primaryPosition.y = cursorInfo.lineOffset;
-
-    // Transform the cursor info from line's coords to text's coords.
-    cursorInfo.primaryPosition.x += ( LTR == line.direction ) ? 0.f : parameters.visualModel->mControlSize.width;
   }
   else
   {
index 9d1b93d..6e8be71 100755 (executable)
@@ -53,6 +53,11 @@ const float MAX_FLOAT = std::numeric_limits<float>::max();
 const bool RTL = true;
 const float LINE_SPACING= 0.f;
 
+inline bool isEmptyLineAtLast( const Vector<LineRun>& lines, const Vector<LineRun>::Iterator& line )
+{
+  return ( (*line).characterRun.numberOfCharacters == 0 && line + 1u == lines.End() );
+}
+
 } //namespace
 
 /**
@@ -1042,12 +1047,18 @@ struct Engine::Impl
         continue;
       }
 
-      if( line.characterRun.characterIndex >= lastCharacterPlusOne )
+      if( line.characterRun.characterIndex > lastCharacterPlusOne )
       {
         // Do not align lines beyond the last laid-out character.
         break;
       }
 
+      if( line.characterRun.characterIndex == lastCharacterPlusOne && !isEmptyLineAtLast( lines, it ) )
+      {
+        // Do not align lines beyond the last laid-out character unless the line is last and empty.
+        break;
+      }
+
       // Calculate the line's alignment offset accordingly with the align option,
       // the box width, line length, and the paragraph's direction.
       CalculateHorizontalAlignment( size.width,
index 44a6788..f82eada 100755 (executable)
@@ -399,6 +399,13 @@ void Controller::SetHorizontalAlignment( Text::HorizontalAlignment::Type alignme
     if( mImpl->mEventData )
     {
       mImpl->mEventData->mUpdateAlignment = true;
+
+      // Update the cursor if it's in editing mode
+      if( EventData::IsEditingState( mImpl->mEventData->mState ) )
+      {
+        mImpl->ChangeState( EventData::EDITING );
+        mImpl->mEventData->mUpdateCursorPosition = true;
+      }
     }
 
     mImpl->RequestRelayout();