Avoid deleting text behind the cursor 43/42243/1
authorPaul Wisbey <p.wisbey@samsung.com>
Wed, 24 Jun 2015 16:25:31 +0000 (17:25 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Wed, 24 Jun 2015 16:26:24 +0000 (17:26 +0100)
Change-Id: I198f70493b9340c67555671b083d8ccb354a249f

dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index 8a42bcb..52c64dd 100644 (file)
@@ -1138,39 +1138,7 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
     }
     else if( Dali::DALI_KEY_BACKSPACE == keyCode )
     {
     }
     else if( Dali::DALI_KEY_BACKSPACE == keyCode )
     {
-      DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
-
-      // IMF manager is no longer handling key-events
-      mImpl->ClearPreEditFlag();
-
-      bool removed( false );
-
-      if ( EventData::SELECTING         == mImpl->mEventData->mState ||
-           EventData::SELECTION_CHANGED == mImpl->mEventData->mState )
-      {
-        removed = RemoveSelectedText();
-      }
-      else
-      {
-        // Remove the character before the current cursor position
-        removed = RemoveText( -1, 1 );
-      }
-
-      if( removed )
-      {
-        if( 0u != mImpl->mLogicalModel->mText.Count() ||
-            !mImpl->IsPlaceholderAvailable() )
-        {
-          mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
-        }
-        else
-        {
-          ShowPlaceholderText();
-          mImpl->mEventData->mUpdateCursorPosition = true;
-        }
-
-        textChanged = true;
-      }
+      textChanged = BackspaceKeyEvent();
     }
     else
     {
     }
     else
     {
@@ -1637,6 +1605,43 @@ Controller::~Controller()
   delete mImpl;
 }
 
   delete mImpl;
 }
 
+bool Controller::BackspaceKeyEvent()
+{
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Controller::KeyEvent %p DALI_KEY_BACKSPACE\n", this );
+
+  // IMF manager is no longer handling key-events
+  mImpl->ClearPreEditFlag();
+
+  bool removed( false );
+
+  if ( EventData::SELECTING         == mImpl->mEventData->mState ||
+       EventData::SELECTION_CHANGED == mImpl->mEventData->mState )
+  {
+    removed = RemoveSelectedText();
+  }
+  else if( mImpl->mEventData->mPrimaryCursorPosition > 0 )
+  {
+    // Remove the character before the current cursor position
+    removed = RemoveText( -1, 1 );
+  }
+
+  if( removed )
+  {
+    if( 0u != mImpl->mLogicalModel->mText.Count() ||
+        !mImpl->IsPlaceholderAvailable() )
+    {
+      mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
+    }
+    else
+    {
+      ShowPlaceholderText();
+      mImpl->mEventData->mUpdateCursorPosition = true;
+    }
+  }
+
+  return removed;
+}
+
 void Controller::ShowPlaceholderText()
 {
   if( mImpl->IsPlaceholderAvailable() )
 void Controller::ShowPlaceholderText()
 {
   if( mImpl->IsPlaceholderAvailable() )
index 8699edd..cac83ee 100644 (file)
@@ -575,6 +575,13 @@ protected:
 private:
 
   /**
 private:
 
   /**
+   * @brief Helper to KeyEvent() to handle the backspace case.
+   *
+   * @return True if a character was deleted.
+   */
+  bool BackspaceKeyEvent();
+
+  /**
    * @brief Helper to clear font-specific data.
    */
   void ShowPlaceholderText();
    * @brief Helper to clear font-specific data.
    */
   void ShowPlaceholderText();