From a53706fd985dcbed954d7438222e4adf898c3500 Mon Sep 17 00:00:00 2001
From: Paul Wisbey
Date: Wed, 24 Jun 2015 17:25:31 +0100
Subject: [PATCH] Avoid deleting text behind the cursor
Change-Id: I198f70493b9340c67555671b083d8ccb354a249f
---
dali-toolkit/internal/text/text-controller.cpp | 71 ++++++++++++++------------
dali-toolkit/internal/text/text-controller.h | 7 +++
2 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp
index 8a42bcb..52c64dd 100644
--- a/dali-toolkit/internal/text/text-controller.cpp
+++ b/dali-toolkit/internal/text/text-controller.cpp
@@ -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() )
diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h
index 8699edd..cac83ee 100644
--- a/dali-toolkit/internal/text/text-controller.h
+++ b/dali-toolkit/internal/text/text-controller.h
@@ -575,6 +575,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.
*/
void ShowPlaceholderText();
--
2.7.4