Fix for Text::Controller::SetText(). 26/40926/4
authorVictor Cebollada <v.cebollada@samsung.com>
Wed, 10 Jun 2015 08:42:39 +0000 (09:42 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Wed, 10 Jun 2015 14:55:48 +0000 (07:55 -0700)
If the controller is in edit mode it updates
the cursor and scroll positions.

Change-Id: Ibff1eeed819e6b348002521c0ad6745649544e7e
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index 49bca2e..36b566b 100644 (file)
@@ -76,6 +76,8 @@ void Controller::SetText( const std::string& text )
   // Remove the previously set text
   ResetText();
 
   // Remove the previously set text
   ResetText();
 
+  CharacterIndex lastCursorIndex = 0u;
+
   if( !text.empty() )
   {
     //  Convert text into UTF-32
   if( !text.empty() )
   {
     //  Convert text into UTF-32
@@ -93,11 +95,8 @@ void Controller::SetText( const std::string& text )
     DALI_ASSERT_DEBUG( text.size() >= characterCount && "Invalid UTF32 conversion length" );
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, text.size(), mImpl->mLogicalModel->mText.Count() );
 
     DALI_ASSERT_DEBUG( text.size() >= characterCount && "Invalid UTF32 conversion length" );
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", this, text.size(), mImpl->mLogicalModel->mText.Count() );
 
-    // Reset the cursor position
-    if( mImpl->mEventData )
-    {
-      mImpl->mEventData->mPrimaryCursorPosition = characterCount;
-    }
+    // To reset the cursor position
+    lastCursorIndex = characterCount;
 
     // Update the rest of the model during size negotiation
     mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
 
     // Update the rest of the model during size negotiation
     mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
@@ -113,6 +112,12 @@ void Controller::SetText( const std::string& text )
     ShowPlaceholderText();
   }
 
     ShowPlaceholderText();
   }
 
+  // Resets the cursor position.
+  ResetCursorPosition( lastCursorIndex );
+
+  // Scrolls the text to make the cursor visible.
+  ResetScrollPosition();
+
   mImpl->RequestRelayout();
 
   if( mImpl->mEventData )
   mImpl->RequestRelayout();
 
   if( mImpl->mEventData )
@@ -672,12 +677,6 @@ void Controller::ResetText()
   mImpl->mLogicalModel->mText.Clear();
   ClearModelData();
 
   mImpl->mLogicalModel->mText.Clear();
   ClearModelData();
 
-  // Reset the cursor position
-  if( mImpl->mEventData )
-  {
-    mImpl->mEventData->mPrimaryCursorPosition = 0;
-  }
-
   // We have cleared everything including the placeholder-text
   mImpl->PlaceholderCleared();
 
   // We have cleared everything including the placeholder-text
   mImpl->PlaceholderCleared();
 
@@ -688,6 +687,32 @@ void Controller::ResetText()
   mImpl->mOperationsPending = ALL_OPERATIONS;
 }
 
   mImpl->mOperationsPending = ALL_OPERATIONS;
 }
 
+void Controller::ResetCursorPosition( CharacterIndex cursorIndex )
+{
+  // Reset the cursor position
+  if( NULL != mImpl->mEventData )
+  {
+    mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
+
+    // Update the cursor if it's in editing mode.
+    if( ( EventData::EDITING == mImpl->mEventData->mState ) ||
+        ( EventData::EDITING_WITH_POPUP == mImpl->mEventData->mState ) )
+    {
+      mImpl->mEventData->mUpdateCursorPosition = true;
+    }
+  }
+}
+
+void Controller::ResetScrollPosition()
+{
+  if( NULL != mImpl->mEventData )
+  {
+    // Reset the scroll position.
+    mImpl->mEventData->mScrollPosition = Vector2::ZERO;
+    mImpl->mEventData->mScrollAfterUpdateCursorPosition = true;
+  }
+}
+
 void Controller::TextReplacedEvent()
 {
   // Reset buffers.
 void Controller::TextReplacedEvent()
 {
   // Reset buffers.
index 6c12dd3..8428699 100644 (file)
@@ -379,6 +379,18 @@ public:
   void ResetText();
 
   /**
   void ResetText();
 
   /**
+   * @brief Used to reset the cursor position after setting a new text.
+   *
+   * @param[in] cursorIndex Where to place the cursor.
+   */
+  void ResetCursorPosition( CharacterIndex cursorIndex );
+
+  /**
+   * @brief Used to reset the scroll position after setting a new text.
+   */
+  void ResetScrollPosition();
+
+  /**
    * @brief Used to process an event queued from SetText()
    */
   void TextReplacedEvent();
    * @brief Used to process an event queued from SetText()
    */
   void TextReplacedEvent();