Whether to update the input style when text is removed. 67/66367/5
authorVictor Cebollada <v.cebollada@samsung.com>
Mon, 18 Apr 2016 10:58:55 +0000 (11:58 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Mon, 25 Apr 2016 07:44:35 +0000 (08:44 +0100)
* When predictve text is used the pre-edit text is removed
  and inserted again with the new characters. This patch
  avoids to update the input style when pre-edit text is
  removed.

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

index 68247ae..3500985 100644 (file)
@@ -508,7 +508,9 @@ const Vector4& Controller::GetTextColor() const
   return mImpl->mTextColor;
 }
 
-bool Controller::RemoveText( int cursorOffset, int numberOfCharacters )
+bool Controller::RemoveText( int cursorOffset,
+                             int numberOfCharacters,
+                             UpdateInputStyleType type )
 {
   bool removed = false;
 
@@ -547,13 +549,16 @@ bool Controller::RemoveText( int cursorOffset, int numberOfCharacters )
 
       // Update the input style and remove the text's style before removing the text.
 
-      // Set first the default input style.
-      mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
+      if( UPDATE_INPUT_STYLE == type )
+      {
+        // Set first the default input style.
+        mImpl->RetrieveDefaultInputStyle( mImpl->mEventData->mInputStyle );
 
-      // Update the input style.
-      mImpl->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
+        // Update the input style.
+        mImpl->mLogicalModel->RetrieveStyle( cursorIndex, mImpl->mEventData->mInputStyle );
+      }
 
-      // Remove the text's style before removing the text.
+      // Updates the text style runs by removing characters. Runs with no characters are removed.
       mImpl->mLogicalModel->UpdateTextStyleRuns( cursorIndex, -numberOfCharacters );
 
       // Remove the characters.
@@ -1804,7 +1809,9 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ
   {
     const CharacterIndex offset = mImpl->mEventData->mPrimaryCursorPosition - mImpl->mEventData->mPreEditStartPosition;
 
-    removedPrevious = RemoveText( -static_cast<int>( offset ), mImpl->mEventData->mPreEditLength );
+    removedPrevious = RemoveText( -static_cast<int>( offset ),
+                                  mImpl->mEventData->mPreEditLength,
+                                  DONT_UPDATE_INPUT_STYLE );
 
     mImpl->mEventData->mPrimaryCursorPosition = mImpl->mEventData->mPreEditStartPosition;
     mImpl->mEventData->mPreEditLength = 0u;
@@ -2373,7 +2380,9 @@ ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, cons
     }
     case ImfManager::DELETESURROUNDING:
     {
-      update = RemoveText( imfEvent.cursorOffset, imfEvent.numberOfChars );
+      update = RemoveText( imfEvent.cursorOffset,
+                           imfEvent.numberOfChars,
+                           DONT_UPDATE_INPUT_STYLE );
 
       if( update )
       {
@@ -2453,7 +2462,9 @@ bool Controller::BackspaceKeyEvent()
   else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
   {
     // Remove the character before the current cursor position
-    removed = RemoveText( -1, 1 );
+    removed = RemoveText( -1,
+                          1,
+                          UPDATE_INPUT_STYLE );
   }
 
   if( removed )
index 546389c..6a83374 100644 (file)
@@ -99,6 +99,15 @@ public:
   };
 
   /**
+   * @brief Used to specify whether to update the input style.
+   */
+  enum UpdateInputStyleType
+  {
+    UPDATE_INPUT_STYLE,
+    DONT_UPDATE_INPUT_STYLE
+  };
+
+  /**
    * @brief Create a new instance of a Controller.
    *
    * @param[in] controlInterface An interface used to request a text relayout.
@@ -157,11 +166,18 @@ public:
   /**
    * @brief Remove a given number of characters
    *
+   * When predictve text is used the pre-edit text is removed and inserted again with the new characters.
+   * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input
+   * style when pre-edit text is removed.
+   *
    * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
    * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset.
+   * @param[in] type Whether to update the input style.
    * @return True if the remove was successful.
    */
-  bool RemoveText( int cursorOffset, int numberOfCharacters );
+  bool RemoveText( int cursorOffset,
+                   int numberOfCharacters,
+                   UpdateInputStyleType type  );
 
   /**
    * @brief Retrieve the current cursor position.