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 8a42bcbccd6b07b79ae3f6f2df147d18fa9036e3..52c64ddbcb7eed720576a2d370d02e6e17854038 100644 (file)
@@ -1138,39 +1138,7 @@ bool Controller::KeyEvent( const Dali::KeyEvent& keyEvent )
     }
     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
     {
@@ -1637,6 +1605,43 @@ Controller::~Controller()
   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() )
index 8699edd985fec688a349b6de2879c0c676b270a2..cac83ee7a7d5c686f9b3b0cc66fd2b939a07cff7 100644 (file)
@@ -574,6 +574,13 @@ protected:
 
 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.
    */