dali-toolkit: fix wrong TextChanged() signal 20/252220/3
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 26 Jan 2021 01:29:45 +0000 (10:29 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Mon, 22 Feb 2021 02:02:07 +0000 (11:02 +0900)
limit the range of DALI_KEY_DELETE to text's length.
in case of no limit,
TextChanged() signal is emitted even if nothing is deleted.

Change-Id: Ie09bc718a88e2aed5b0c7cf9ebeef6042b63de5b
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp
dali-toolkit/internal/text/text-controller-event-handler.cpp

index 66f8db3..d5a243c 100644 (file)
@@ -975,6 +975,19 @@ int utcDaliTextEditorTextChangedP(void)
   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
   DALI_TEST_CHECK( gTextChangedCallBackCalled );
 
+  // Remove all text
+  editor.SetProperty( TextField::Property::TEXT, "" );
+
+  // Pressing backspace key: TextChangedCallback should not be called when there is no text in texteditor.
+  gTextChangedCallBackCalled = false;
+  application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+  DALI_TEST_CHECK( !gTextChangedCallBackCalled );
+
+  // Pressing delete key: TextChangedCallback should not be called when there is no text in texteditor.
+  gTextChangedCallBackCalled = false;
+  application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+  DALI_TEST_CHECK( !gTextChangedCallBackCalled );
+
   END_TEST;
 }
 
index 93d8f7d..b535059 100644 (file)
@@ -1045,6 +1045,19 @@ int utcDaliTextFieldTextChangedP(void)
   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
   DALI_TEST_CHECK( gTextChangedCallBackCalled );
 
+  // Remove all text
+  field.SetProperty( TextField::Property::TEXT, "" );
+
+  // Pressing backspace key: TextChangedCallback should not be called when there is no text in textfield.
+  gTextChangedCallBackCalled = false;
+  application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+  DALI_TEST_CHECK( !gTextChangedCallBackCalled );
+
+  // Pressing delete key: TextChangedCallback should not be called when there is no text in textfield.
+  gTextChangedCallBackCalled = false;
+  application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
+  DALI_TEST_CHECK( !gTextChangedCallBackCalled );
+
   END_TEST;
 }
 
index c6fbe87..c6c4058 100644 (file)
@@ -599,7 +599,8 @@ bool Controller::EventHandler::DeleteEvent(Controller& controller, int keyCode)
                                     1,
                                     UPDATE_INPUT_STYLE);
   }
-  else if(keyCode == Dali::DevelKey::DALI_KEY_DELETE)
+  else if((controller.mImpl->mEventData->mPrimaryCursorPosition < controller.mImpl->mModel->mLogicalModel->mText.Count()) &&
+          (keyCode == Dali::DevelKey::DALI_KEY_DELETE))
   {
     // Remove the character after the current cursor position
     removed = controller.RemoveText(0,