From 05456785d7bfcc34f1bee09df6b30ceb8f6ff24f Mon Sep 17 00:00:00 2001 From: "minho.sun" Date: Wed, 27 Dec 2017 16:55:49 +0900 Subject: [PATCH] Check line is empty or not before getting line of character mLine can be empty Vector if there is no text or place holder in text-editor / text-field. So check mLine is empty or not first and if it is empty, return 0u. Change-Id: I950ca6df885080d84bc8c6a7055d0afcce21d8c5 --- automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp | 7 +++++++ dali-toolkit/internal/text/visual-model-impl.cpp | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index 07f1cac..a8f2c9d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1631,6 +1632,12 @@ int utcDaliTextFieldEvent01(void) application.SendNotification(); application.Render(); + // Pressing delete key should be fine even if there is no text in TextField. + application.ProcessEvent( GenerateKey( "Delete", "Delete", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + // Render and notify + application.SendNotification(); + application.Render(); + // Now the text field has the focus, so it can handle the key events. application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); diff --git a/dali-toolkit/internal/text/visual-model-impl.cpp b/dali-toolkit/internal/text/visual-model-impl.cpp index 5373a6a..e359dc7 100755 --- a/dali-toolkit/internal/text/visual-model-impl.cpp +++ b/dali-toolkit/internal/text/visual-model-impl.cpp @@ -264,18 +264,21 @@ void VisualModel::GetLinesOfGlyphRange( LineRun* lines, LineIndex VisualModel::GetLineOfCharacter( CharacterIndex characterIndex ) { - // 1) Check first in the cached line. + // 1) Check line is empty or not. + if( mLines.Empty() ) + { + return 0u; + } + // 2) Check in the cached line. const LineRun& lineRun = *( mLines.Begin() + mCachedLineIndex ); - if( ( lineRun.characterRun.characterIndex <= characterIndex ) && ( characterIndex < lineRun.characterRun.characterIndex + lineRun.characterRun.numberOfCharacters ) ) { return mCachedLineIndex; } - // 2) Is not in the cached line. Check in the other lines. - + // 3) Is not in the cached line. Check in the other lines. LineIndex index = characterIndex < lineRun.characterRun.characterIndex ? 0u : mCachedLineIndex + 1u; for( Vector::ConstIterator it = mLines.Begin() + index, -- 2.7.4