X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller-impl.cpp;h=26fb42254684f0a2ede8ffcc09e9b52a73d246d8;hp=76e42cad87e128b376eac9fd5926c70606dc36aa;hb=e4f601ea17cf4b2bb7da1393a62520ec147437c5;hpb=85b83b75993f7e01302d67c19aa53c3e1fc63586 diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 76e42ca..26fb422 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -25,13 +25,9 @@ // INTERNAL INCLUDES #include #include -#include #include -#include #include #include -#include -#include namespace { @@ -1004,7 +1000,7 @@ void Controller::Impl::RepositionSelectionHandles( CharacterIndex selectionStart mEventData->mDecorator->AddHighlight( xPosition, offset.y, xPosition + static_cast( numberOfCharacters ) * glyphAdvance, - height ); + offset.y + height ); splitStartGlyph = false; continue; @@ -1029,14 +1025,17 @@ void Controller::Impl::RepositionSelectionHandles( CharacterIndex selectionStart mEventData->mDecorator->AddHighlight( xPosition, offset.y, xPosition + static_cast( interGlyphIndex ) * glyphAdvance, - height ); + offset.y + height ); splitEndGlyph = false; continue; } const float xPosition = position.x - glyph.xBearing + offset.x; - mEventData->mDecorator->AddHighlight( xPosition, offset.y, xPosition + glyph.advance, height ); + mEventData->mDecorator->AddHighlight( xPosition, + offset.y, + xPosition + glyph.advance, + offset.y + height ); } CursorInfo primaryCursorInfo; @@ -1054,6 +1053,9 @@ void Controller::Impl::RepositionSelectionHandles( CharacterIndex selectionStart mEventData->mDecorator->SetPosition( RIGHT_SELECTION_HANDLE, secondaryPosition.x, secondaryPosition.y, secondaryCursorInfo.lineHeight ); + // Cursor to be positioned at end of selection so if selection interrupted and edit mode restarted the cursor will be at end of selection + mEventData->mPrimaryCursorPosition = (indicesSwapped)?mEventData->mLeftSelectionPosition:mEventData->mRightSelectionPosition; + // Set the flag to update the decorator. mEventData->mDecoratorUpdated = true; } @@ -1318,10 +1320,25 @@ LineIndex Controller::Impl::GetClosestLine( float y ) const void Controller::Impl::FindSelectionIndices( float visualX, float visualY, CharacterIndex& startIndex, CharacterIndex& endIndex ) { CharacterIndex hitCharacter = GetClosestCursorIndex( visualX, visualY ); + DALI_ASSERT_DEBUG( hitCharacter <= mLogicalModel->mText.Count() && "GetClosestCursorIndex returned out of bounds index" ); + + if ( mLogicalModel->mText.Count() == 0 ) + { + return; // if model empty + } + if( hitCharacter >= mLogicalModel->mText.Count() ) { - // Selection out of bounds. - return; + // Closest hit character is the last character. + if ( hitCharacter == mLogicalModel->mText.Count() ) + { + hitCharacter--; //Hit character index set to last character in logical model + } + else + { + // hitCharacter is out of bounds + return; + } } startIndex = hitCharacter; @@ -1353,6 +1370,8 @@ void Controller::Impl::FindSelectionIndices( float visualX, float visualY, Chara CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, float visualY ) { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetClosestCursorIndex %p closest visualX %f visualY %f\n", this, visualX, visualY ); + if( NULL == mEventData ) { // Nothing to do if there is no text input. @@ -1456,6 +1475,8 @@ CharacterIndex Controller::Impl::GetClosestCursorIndex( float visualX, logicalIndex = hasRightToLeftCharacters ? *( visualToLogicalCursorBuffer + visualIndex ) : visualIndex; DALI_LOG_INFO( gLogFilter, Debug::Verbose, "%p closest visualIndex %d logicalIndex %d\n", this, visualIndex, logicalIndex ); + DALI_ASSERT_DEBUG( ( logicalIndex <= mLogicalModel->mText.Count() && logicalIndex >= 0 ) && "GetClosestCursorIndex - Out of bounds index" ); + return logicalIndex; } @@ -1474,7 +1495,7 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, cursorInfo.lineHeight = GetDefaultFontLineHeight(); cursorInfo.primaryCursorHeight = cursorInfo.lineHeight; - cursorInfo.primaryPosition.x = 1.f; + cursorInfo.primaryPosition.x = mEventData->mDecorator->GetCursorWidth(); cursorInfo.primaryPosition.y = 0.f; // Nothing else to do. @@ -1710,7 +1731,7 @@ void Controller::Impl::UpdateCursorPosition() return; } - if( IsShowingPlaceholderText() ) + if( IsShowingPlaceholderText() || ( 0u == mLogicalModel->mText.Count() ) ) { // Do not want to use the place-holder text to set the cursor position. @@ -1743,7 +1764,7 @@ void Controller::Impl::UpdateCursorPosition() { case LayoutEngine::HORIZONTAL_ALIGN_BEGIN: { - cursorPosition.x = 1.f; + cursorPosition.x = mEventData->mDecorator->GetCursorWidth(); break; } case LayoutEngine::HORIZONTAL_ALIGN_CENTER: @@ -1955,8 +1976,9 @@ void Controller::Impl::ScrollTextToMatchCursor() } // Set which cursors are active according the state. - if( ( EventData::EDITING == mEventData->mState ) || - ( EventData::EDITING_WITH_POPUP == mEventData->mState ) || + if( ( EventData::EDITING == mEventData->mState ) || + ( EventData::EDITING_WITH_POPUP == mEventData->mState ) || + ( EventData::EDITING_WITH_GRAB_HANDLE == mEventData->mState ) || ( EventData::GRAB_HANDLE_PANNING == mEventData->mState ) ) { if( cursorInfo.isSecondaryCursor )