From 90c3769b5825892e7093ab32862ee3836036614b Mon Sep 17 00:00:00 2001 From: Ali Alzyod Date: Tue, 22 Sep 2020 19:37:38 +0300 Subject: [PATCH] Dali-Text: Keyboard Shortcut (language layout independent) Keyboard shortcuts like (CTRL+A) to select all text, will work regardless of keyboard language layout. Before Change: If keyboard language layout is Arabic, (CTRL+A) will not work. After Change: (CTRL+A) will work, regardless of language layout for keyboard. Change-Id: I44708a85c9499dc54e0d36758f039c0907ee70a2 --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 48 ++++++++++++++++++++++ .../text/text-controller-event-handler.cpp | 11 +++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 7a3ce4c..b6f3da8 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -2172,6 +2172,54 @@ int utcDaliTextEditorEvent07(void) //text is "c" DALI_TEST_EQUALS( "c", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + // select all text + DevelTextEditor::SelectWholeText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Copy the selected text using logical keys + application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_CONTROL_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "ؤ", "c", "ؤ", KEY_C_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "c", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // select none + DevelTextEditor::SelectNone(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Paste the selected using logical keys + application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_CONTROL_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "ر", "v", "ر", KEY_V_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "v", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + //text is "cc" + DALI_TEST_EQUALS( "cc", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + + // select all using logical keys + application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_CONTROL_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "ش", "a", "ش", KEY_A_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // cut text using logical keys + application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_CONTROL_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "ء", "x", "ء", KEY_X_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "x", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + //text is "" + DALI_TEST_EQUALS( "", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + END_TEST; } diff --git a/dali-toolkit/internal/text/text-controller-event-handler.cpp b/dali-toolkit/internal/text/text-controller-event-handler.cpp index b9b260b..89ff0f9 100644 --- a/dali-toolkit/internal/text/text-controller-event-handler.cpp +++ b/dali-toolkit/internal/text/text-controller-event-handler.cpp @@ -109,6 +109,9 @@ bool Controller::EventHandler::KeyEvent(Controller& controller, const Dali::KeyE int keyCode = keyEvent.GetKeyCode(); const std::string& keyString = keyEvent.GetKeyString(); const std::string keyName = keyEvent.GetKeyName(); + // Key will produce same logical-key value when ctrl + // is down, regardless of language layout + const std::string logicalKey = keyEvent.GetLogicalKey(); const bool isNullKey = ( 0 == keyCode ) && ( keyString.empty() ); @@ -182,25 +185,25 @@ bool Controller::EventHandler::KeyEvent(Controller& controller, const Dali::KeyE else if ( keyEvent.IsCtrlModifier() && !keyEvent.IsShiftModifier()) { bool consumed = false; - if (keyName == KEY_C_NAME || keyName == KEY_INSERT_NAME) + if (keyName == KEY_C_NAME || keyName == KEY_INSERT_NAME || logicalKey == KEY_C_NAME || logicalKey == KEY_INSERT_NAME) { // Ctrl-C or Ctrl+Insert to copy the selected text controller.TextPopupButtonTouched( Toolkit::TextSelectionPopup::COPY ); consumed = true; } - else if (keyName == KEY_V_NAME) + else if (keyName == KEY_V_NAME || logicalKey == KEY_V_NAME) { // Ctrl-V to paste the copied text controller.TextPopupButtonTouched( Toolkit::TextSelectionPopup::PASTE ); consumed = true; } - else if (keyName == KEY_X_NAME) + else if (keyName == KEY_X_NAME || logicalKey == KEY_X_NAME) { // Ctrl-X to cut the selected text controller.TextPopupButtonTouched( Toolkit::TextSelectionPopup::CUT ); consumed = true; } - else if (keyName == KEY_A_NAME) + else if (keyName == KEY_A_NAME || logicalKey == KEY_A_NAME) { // Ctrl-A to select All the text controller.TextPopupButtonTouched( Toolkit::TextSelectionPopup::SELECT_ALL ); -- 2.7.4