Merge "Dali-Text: Keyboard Shortcuts" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index 8aaefae..48036ad 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -53,6 +53,8 @@ const std::string EMPTY_STRING("");
 const std::string KEY_C_NAME = "c";
 const std::string KEY_V_NAME = "v";
 const std::string KEY_X_NAME = "x";
+const std::string KEY_A_NAME = "a";
+const std::string KEY_INSERT_NAME = "Insert";
 
 const char * const PLACEHOLDER_TEXT = "text";
 const char * const PLACEHOLDER_TEXT_FOCUSED = "textFocused";
@@ -835,6 +837,16 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
   DALI_LOG_INFO( gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
   mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
 
+  if( mImpl->mEventData )
+  {
+    // Update the cursor position if it's in editing mode
+    if( EventData::IsEditingState( mImpl->mEventData->mState ) )
+    {
+      mImpl->mEventData->mDecoratorUpdated = true;
+      mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
+    }
+  }
+
   // Clear the font-specific data
   ClearFontData();
 
@@ -888,6 +900,16 @@ void Controller::SetDefaultFontWeight( FontWeight weight )
   mImpl->mFontDefaults->mFontDescription.weight = weight;
   mImpl->mFontDefaults->weightDefined = true;
 
+  if( mImpl->mEventData )
+  {
+    // Update the cursor position if it's in editing mode
+    if( EventData::IsEditingState( mImpl->mEventData->mState ) )
+    {
+      mImpl->mEventData->mDecoratorUpdated = true;
+      mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
+    }
+  }
+
   // Clear the font-specific data
   ClearFontData();
 
@@ -959,6 +981,16 @@ void Controller::SetDefaultFontWidth( FontWidth width )
   mImpl->mFontDefaults->mFontDescription.width = width;
   mImpl->mFontDefaults->widthDefined = true;
 
+  if( mImpl->mEventData )
+  {
+    // Update the cursor position if it's in editing mode
+    if( EventData::IsEditingState( mImpl->mEventData->mState ) )
+    {
+      mImpl->mEventData->mDecoratorUpdated = true;
+      mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
+    }
+  }
+
   // Clear the font-specific data
   ClearFontData();
 
@@ -1030,6 +1062,16 @@ void Controller::SetDefaultFontSlant( FontSlant slant )
   mImpl->mFontDefaults->mFontDescription.slant = slant;
   mImpl->mFontDefaults->slantDefined = true;
 
+  if( mImpl->mEventData )
+  {
+    // Update the cursor position if it's in editing mode
+    if( EventData::IsEditingState( mImpl->mEventData->mState ) )
+    {
+      mImpl->mEventData->mDecoratorUpdated = true;
+      mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
+    }
+  }
+
   // Clear the font-specific data
   ClearFontData();
 
@@ -1119,6 +1161,16 @@ void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
     }
   }
 
+  if( mImpl->mEventData )
+  {
+    // Update the cursor position if it's in editing mode
+    if( EventData::IsEditingState( mImpl->mEventData->mState ) )
+    {
+      mImpl->mEventData->mDecoratorUpdated = true;
+      mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
+    }
+  }
+
   // Clear the font-specific data
   ClearFontData();
 
@@ -1462,6 +1514,22 @@ float Controller::GetDefaultLineSpacing() const
   return mImpl->mLayoutEngine.GetDefaultLineSpacing();
 }
 
+bool Controller::SetDefaultLineSize( float lineSize )
+{
+  if( std::fabs( lineSize - mImpl->mLayoutEngine.GetDefaultLineSize() ) > Math::MACHINE_EPSILON_1000 )
+  {
+    mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
+    mImpl->mRecalculateNaturalSize = true;
+    return true;
+  }
+  return false;
+}
+
+float Controller::GetDefaultLineSize() const
+{
+  return mImpl->mLayoutEngine.GetDefaultLineSize();
+}
+
 void Controller::SetInputColor( const Vector4& color )
 {
   if( NULL != mImpl->mEventData )
@@ -1520,17 +1588,32 @@ void Controller::SetInputFontFamily( const std::string& fontFamily )
     {
       CharacterIndex startOfSelectedText = 0u;
       Length lengthOfSelectedText = 0u;
-      FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
-                                                                            mImpl->mModel->mLogicalModel,
-                                                                            startOfSelectedText,
-                                                                            lengthOfSelectedText );
 
-      fontDescriptionRun.familyLength = fontFamily.size();
-      fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
-      memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
-      fontDescriptionRun.familyDefined = true;
+      if( EventData::SELECTING == mImpl->mEventData->mState )
+      {
+        // Update a font description run for the selecting state.
+        FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
+                                                                              mImpl->mModel->mLogicalModel,
+                                                                              startOfSelectedText,
+                                                                              lengthOfSelectedText );
 
-      // The memory allocated for the font family name is freed when the font description is removed from the logical model.
+        fontDescriptionRun.familyLength = fontFamily.size();
+        fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
+        memcpy( fontDescriptionRun.familyName, fontFamily.c_str(), fontDescriptionRun.familyLength );
+        fontDescriptionRun.familyDefined = true;
+
+        // The memory allocated for the font family name is freed when the font description is removed from the logical model.
+
+        mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
+      }
+      else
+      {
+        mImpl->mTextUpdateInfo.mCharacterIndex = 0;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
+      }
 
       // Request to relayout.
       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
@@ -1544,10 +1627,6 @@ void Controller::SetInputFontFamily( const std::string& fontFamily )
       mImpl->mRecalculateNaturalSize = true;
       mImpl->RequestRelayout();
 
-      mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
-
       // As the font changes, recalculate the handle positions is needed.
       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
       mImpl->mEventData->mUpdateRightSelectionPosition = true;
@@ -1579,13 +1658,28 @@ void Controller::SetInputFontWeight( FontWeight weight )
     {
       CharacterIndex startOfSelectedText = 0u;
       Length lengthOfSelectedText = 0u;
-      FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
-                                                                            mImpl->mModel->mLogicalModel,
-                                                                            startOfSelectedText,
-                                                                            lengthOfSelectedText );
 
-      fontDescriptionRun.weight = weight;
-      fontDescriptionRun.weightDefined = true;
+      if( EventData::SELECTING == mImpl->mEventData->mState )
+      {
+        // Update a font description run for the selecting state.
+        FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
+                                                                              mImpl->mModel->mLogicalModel,
+                                                                              startOfSelectedText,
+                                                                              lengthOfSelectedText );
+
+        fontDescriptionRun.weight = weight;
+        fontDescriptionRun.weightDefined = true;
+
+        mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
+      }
+      else
+      {
+        mImpl->mTextUpdateInfo.mCharacterIndex = 0;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
+      }
 
       // Request to relayout.
       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
@@ -1599,10 +1693,6 @@ void Controller::SetInputFontWeight( FontWeight weight )
       mImpl->mRecalculateNaturalSize = true;
       mImpl->RequestRelayout();
 
-      mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
-
       // As the font might change, recalculate the handle positions is needed.
       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
       mImpl->mEventData->mUpdateRightSelectionPosition = true;
@@ -1645,13 +1735,28 @@ void Controller::SetInputFontWidth( FontWidth width )
     {
       CharacterIndex startOfSelectedText = 0u;
       Length lengthOfSelectedText = 0u;
-      FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
-                                                                            mImpl->mModel->mLogicalModel,
-                                                                            startOfSelectedText,
-                                                                            lengthOfSelectedText );
 
-      fontDescriptionRun.width = width;
-      fontDescriptionRun.widthDefined = true;
+      if( EventData::SELECTING == mImpl->mEventData->mState )
+      {
+        // Update a font description run for the selecting state.
+        FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
+                                                                              mImpl->mModel->mLogicalModel,
+                                                                              startOfSelectedText,
+                                                                              lengthOfSelectedText );
+
+        fontDescriptionRun.width = width;
+        fontDescriptionRun.widthDefined = true;
+
+        mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
+      }
+      else
+      {
+        mImpl->mTextUpdateInfo.mCharacterIndex = 0;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
+      }
 
       // Request to relayout.
       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
@@ -1665,10 +1770,6 @@ void Controller::SetInputFontWidth( FontWidth width )
       mImpl->mRecalculateNaturalSize = true;
       mImpl->RequestRelayout();
 
-      mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
-
       // As the font might change, recalculate the handle positions is needed.
       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
       mImpl->mEventData->mUpdateRightSelectionPosition = true;
@@ -1711,13 +1812,28 @@ void Controller::SetInputFontSlant( FontSlant slant )
     {
       CharacterIndex startOfSelectedText = 0u;
       Length lengthOfSelectedText = 0u;
-      FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
-                                                                            mImpl->mModel->mLogicalModel,
-                                                                            startOfSelectedText,
-                                                                            lengthOfSelectedText );
 
-      fontDescriptionRun.slant = slant;
-      fontDescriptionRun.slantDefined = true;
+      if( EventData::SELECTING == mImpl->mEventData->mState )
+      {
+        // Update a font description run for the selecting state.
+        FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
+                                                                              mImpl->mModel->mLogicalModel,
+                                                                              startOfSelectedText,
+                                                                              lengthOfSelectedText );
+
+        fontDescriptionRun.slant = slant;
+        fontDescriptionRun.slantDefined = true;
+
+        mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
+      }
+      else
+      {
+        mImpl->mTextUpdateInfo.mCharacterIndex = 0;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
+      }
 
       // Request to relayout.
       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
@@ -1731,10 +1847,6 @@ void Controller::SetInputFontSlant( FontSlant slant )
       mImpl->mRecalculateNaturalSize = true;
       mImpl->RequestRelayout();
 
-      mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
-
       // As the font might change, recalculate the handle positions is needed.
       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
       mImpl->mEventData->mUpdateRightSelectionPosition = true;
@@ -1777,13 +1889,28 @@ void Controller::SetInputFontPointSize( float size )
     {
       CharacterIndex startOfSelectedText = 0u;
       Length lengthOfSelectedText = 0u;
-      FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
-                                                                            mImpl->mModel->mLogicalModel,
-                                                                            startOfSelectedText,
-                                                                            lengthOfSelectedText );
 
-      fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
-      fontDescriptionRun.sizeDefined = true;
+      if( EventData::SELECTING == mImpl->mEventData->mState )
+      {
+        // Update a font description run for the selecting state.
+        FontDescriptionRun& fontDescriptionRun = UpdateSelectionFontStyleRun( mImpl->mEventData,
+                                                                              mImpl->mModel->mLogicalModel,
+                                                                              startOfSelectedText,
+                                                                              lengthOfSelectedText );
+
+        fontDescriptionRun.size = static_cast<PointSize26Dot6>( size * 64.f );
+        fontDescriptionRun.sizeDefined = true;
+
+        mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
+      }
+      else
+      {
+        mImpl->mTextUpdateInfo.mCharacterIndex = 0;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
+      }
 
       // Request to relayout.
       mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
@@ -1797,10 +1924,6 @@ void Controller::SetInputFontPointSize( float size )
       mImpl->mRecalculateNaturalSize = true;
       mImpl->RequestRelayout();
 
-      mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
-      mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
-
       // As the font might change, recalculate the handle positions is needed.
       mImpl->mEventData->mUpdateLeftSelectionPosition = true;
       mImpl->mEventData->mUpdateRightSelectionPosition = true;
@@ -2709,11 +2832,11 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
   bool relayoutNeeded = false;
 
   if( ( NULL != mImpl->mEventData ) &&
-      ( keyEvent.state == KeyEvent::Down ) )
+      ( keyEvent.GetState() == KeyEvent::DOWN ) )
   {
-    int keyCode = keyEvent.keyCode;
-    const std::string& keyString = keyEvent.keyPressed;
-    const std::string keyName = keyEvent.keyPressedName;
+    int keyCode = keyEvent.GetKeyCode();
+    const std::string& keyString = keyEvent.GetKeyString();
+    const std::string keyName = keyEvent.GetKeyName();
 
     const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() );
 
@@ -2784,12 +2907,12 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
       // Do nothing
       return false;
     }
-    else if ( keyEvent.IsCtrlModifier() )
+    else if ( keyEvent.IsCtrlModifier() && !keyEvent.IsShiftModifier())
     {
       bool consumed = false;
-      if (keyName == KEY_C_NAME)
+      if (keyName == KEY_C_NAME || keyName == KEY_INSERT_NAME)
       {
-        // Ctrl-C to copy the selected text
+        // Ctrl-C or Ctrl+Insert to copy the selected text
         TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY );
         consumed = true;
       }
@@ -2805,6 +2928,12 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
         TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT );
         consumed = true;
       }
+      else if (keyName == KEY_A_NAME)
+      {
+        // Ctrl-A to select All the text
+        TextPopupButtonTouched( Toolkit::TextSelectionPopup::SELECT_ALL );
+        consumed = true;
+      }
       return consumed;
     }
     else if( ( Dali::DALI_KEY_BACKSPACE == keyCode ) ||
@@ -2970,14 +3099,14 @@ void Controller::TapEvent( unsigned int tapCount, float x, float y )
   mImpl->ResetInputMethodContext();
 }
 
-void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
+void Controller::PanEvent( GestureState state, const Vector2& displacement )
 {
   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected PanEvent" );
 
   if( NULL != mImpl->mEventData )
   {
     Event event( Event::PAN_EVENT );
-    event.p1.mInt = state;
+    event.p1.mInt = static_cast<int>( state );
     event.p2.mFloat = displacement.x;
     event.p3.mFloat = displacement.y;
     mImpl->mEventData->mEventQueue.push_back( event );
@@ -2986,11 +3115,11 @@ void Controller::PanEvent( Gesture::State state, const Vector2& displacement )
   }
 }
 
-void Controller::LongPressEvent( Gesture::State state, float x, float y  )
+void Controller::LongPressEvent( GestureState state, float x, float y  )
 {
   DALI_ASSERT_DEBUG( mImpl->mEventData && "Unexpected LongPressEvent" );
 
-  if( ( state == Gesture::Started ) &&
+  if( ( state == GestureState::STARTED ) &&
       ( NULL != mImpl->mEventData ) )
   {
     // The 1st long-press on inactive text-field is treated as tap
@@ -3009,7 +3138,7 @@ void Controller::LongPressEvent( Gesture::State state, float x, float y  )
     else if( !mImpl->IsShowingRealText() )
     {
       Event event( Event::LONG_PRESS_EVENT );
-      event.p1.mInt = state;
+      event.p1.mInt = static_cast<int>( state );
       event.p2.mFloat = x;
       event.p3.mFloat = y;
       mImpl->mEventData->mEventQueue.push_back( event );
@@ -3021,7 +3150,7 @@ void Controller::LongPressEvent( Gesture::State state, float x, float y  )
       mImpl->ResetInputMethodContext();
 
       Event event( Event::LONG_PRESS_EVENT );
-      event.p1.mInt = state;
+      event.p1.mInt = static_cast<int>( state );
       event.p2.mFloat = x;
       event.p3.mFloat = y;
       mImpl->mEventData->mEventQueue.push_back( event );
@@ -3033,17 +3162,22 @@ void Controller::LongPressEvent( Gesture::State state, float x, float y  )
   }
 }
 
-void Controller::SelectEvent( float x, float y, bool selectAll )
+void Controller::SelectEvent( float x, float y, SelectionType selectType )
 {
   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::SelectEvent\n" );
 
   if( NULL != mImpl->mEventData )
   {
-    if( selectAll )
+    if( selectType == SelectionType::ALL )
     {
       Event event( Event::SELECT_ALL );
       mImpl->mEventData->mEventQueue.push_back( event );
     }
+    else if( selectType == SelectionType::NONE )
+    {
+      Event event( Event::SELECT_NONE );
+      mImpl->mEventData->mEventQueue.push_back( event );
+    }
     else
     {
       Event event( Event::SELECT );
@@ -3326,14 +3460,14 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt
       if( mImpl->mEventData->mSelectionEnabled )
       {
         // Creates a SELECT event.
-        SelectEvent( currentCursorPosition.x, currentCursorPosition.y, false );
+        SelectEvent( currentCursorPosition.x, currentCursorPosition.y, SelectionType::INTERACTIVE );
       }
       break;
     }
     case Toolkit::TextSelectionPopup::SELECT_ALL:
     {
       // Creates a SELECT_ALL event
-      SelectEvent( 0.f, 0.f, true );
+      SelectEvent( 0.f, 0.f, SelectionType::ALL );
       break;
     }
     case Toolkit::TextSelectionPopup::CLIPBOARD:
@@ -3707,6 +3841,7 @@ bool Controller::RemoveText( int cursorOffset,
       if( ( currentText.Count() - numberOfCharacters == 0 ) && ( cursorIndex == 0 ) )
       {
         mImpl->ClearPreEditFlag();
+        mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = 0;
       }
 
       // Updates the text style runs by removing characters. Runs with no characters are removed.
@@ -3755,6 +3890,16 @@ bool Controller::RemoveSelectedText()
   return textRemoved;
 }
 
+std::string Controller::GetSelectedText()
+{
+  std::string text;
+  if( EventData::SELECTING == mImpl->mEventData->mState )
+  {
+    mImpl->RetrieveSelection( text, false );
+  }
+  return text;
+}
+
 // private : Relayout.
 
 bool Controller::DoRelayout( const Size& size,
@@ -4013,7 +4158,7 @@ void Controller::ProcessModifyEvents()
     mImpl->mEventData->mRightSelectionPosition = mImpl->mEventData->mPrimaryCursorPosition;
   }
 
-  // Discard temporary text
+  // DISCARD temporary text
   events.Clear();
 }