void Controller::Impl::RepositionSelectionHandles( CharacterIndex selectionStart, CharacterIndex selectionEnd )
{
+ if( selectionStart == selectionEnd )
+ {
+ // Nothing to select if handles are in the same place.
+ return;
+ }
+
mEventData->mDecorator->ClearHighlights();
mEventData->mLeftSelectionPosition = selectionStart;
// TODO: Multi-line.
const Vector<LineRun>& lines = mVisualModel->mLines;
- const float height = lines[0].ascender + -lines[0].descender;
+ const LineRun& firstLine = *lines.Begin();
+ const float height = firstLine.ascender + -firstLine.descender;
- const bool indicesSwapped = selectionStart > selectionEnd;
+ const bool indicesSwapped = ( selectionStart > selectionEnd );
if( indicesSwapped )
{
std::swap( selectionStart, selectionEnd );
GlyphIndex glyphStart = *( charactersToGlyphBuffer + selectionStart );
GlyphIndex glyphEnd = *( charactersToGlyphBuffer + ( selectionEnd - 1u ) ) + *( glyphsPerCharacterBuffer + ( selectionEnd - 1u ) ) - 1u;
- mEventData->mDecorator->SwapSelectionHandlesEnabled( indicesSwapped );
+ mEventData->mDecorator->SwapSelectionHandlesEnabled( firstLine.direction != indicesSwapped );
const Vector2 offset = mEventData->mScrollPosition + mAlignmentOffset;
mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, true );
if( mEventData->mGrabHandlePopupEnabled )
{
+ TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY );
+ if ( !IsClipboardEmpty() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
+ }
+
+ mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
+ mEventData->mDecorator->SetPopupActive( true );
+ }
+ mEventData->mDecoratorUpdated = true;
+ }
+ else if ( EventData::SELECTION_CHANGED == mEventData->mState )
+ {
+ if( mEventData->mGrabHandlePopupEnabled )
+ {
+ TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::CUT | TextSelectionPopup::COPY );
+ if ( !IsClipboardEmpty() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
+ }
+ mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
mEventData->mDecorator->SetPopupActive( true );
}
mEventData->mDecoratorUpdated = true;
}
if( mEventData->mGrabHandlePopupEnabled )
{
+ TextSelectionPopup::Buttons buttonsToShow = TextSelectionPopup::Buttons( TextSelectionPopup::SELECT | TextSelectionPopup::SELECT_ALL );
+
+ if ( !IsClipboardEmpty() )
+ {
+ buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
+ }
+
+ mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
mEventData->mDecorator->SetPopupActive( true );
}
mEventData->mDecoratorUpdated = true;