- // deleted text is within the same line. (merge lines could be needed if the line separator character is deleted)
-
- // Line which contains the characters to be deleted.
- LineLayoutInfo& lineLayout( *( relayoutData.mTextLayoutInfo.mLinesLayoutInfo.begin() + textInfoIndicesBegin.mLineIndex ) );
-
- const WordGroupLayoutInfo& groupLayout( *( lineLayout.mWordGroupsLayoutInfo.begin() + textInfoIndicesBegin.mGroupIndex ) ); // used to check the number of characters of the group of words
- // if all characters to be deleted are in the same group of words.
- if( textInfoIndicesBegin.mGroupIndex < textInfoIndicesEnd.mGroupIndex )
- {
- // Deleted text is from different group of words. The two different group of words may be merged if they have text with same direction.
-
- // whether first or last group of words need to be split and merged with the last part.
- bool splitFirstGroup = false;
- bool splitLastGroup = true;
-
- textInfoMergeIndicesBegin.mGroupIndex = textInfoIndicesBegin.mGroupIndex;
- textInfoMergeIndicesEnd.mGroupIndex = textInfoIndicesEnd.mGroupIndex;
-
- if( ( textInfoIndicesBegin.mWordIndex > 0 ) || ( textInfoIndicesBegin.mCharacterIndex > 0 ) )
- {
- // first character to be deleted is not the first one of the current group.
- ++textInfoIndicesBegin.mGroupIndex; // won't delete current group
-
- // As some characters remain, this group needs to be split and could be merged with the last one.
- splitFirstGroup = true;
- }
-
- // Check if all characters of the last group are going to be deleted.
- const WordGroupLayoutInfo& lastGroupLayout( *( lineLayout.mWordGroupsLayoutInfo.begin() + textInfoIndicesEnd.mGroupIndex ) );
- if( textInfoIndicesEnd.mWordIndex + 1 == lastGroupLayout.mWordsLayoutInfo.size() )
- {
- const WordLayoutInfo& lastWordLayout( *( lastGroupLayout.mWordsLayoutInfo.begin() + textInfoIndicesEnd.mWordIndex ) );
- if( textInfoIndicesEnd.mCharacterIndex + 1 == lastWordLayout.mCharactersLayoutInfo.size() )
- {
- // All characters of the last group are going to be deleted.
- ++textInfoIndicesEnd.mGroupIndex; // will delete the last group.
-
- // The whole last group is deleted. No need to merge groups.
- splitLastGroup = false;
- }
- }
-
- // Only merge two groups if they are not deleted completely and they have same direction.
- mergeGroups = ( splitFirstGroup && splitLastGroup ) && ( groupLayout.mDirection == lastGroupLayout.mDirection );
-
- if( mergeGroups )
- {
- // last group is going to be merged.
- ++textInfoIndicesEnd.mGroupIndex; // will delete the last group.
- }
-
- if( splitFirstGroup )
- {
- // Remove characters from the first group.
-
- // As wordGroupIndexBegin has been increased just to not to remove the group of words, decrease now is needed to access it.
- WordGroupLayoutInfo& groupLayout( *( lineLayout.mWordGroupsLayoutInfo.begin() + textInfoIndicesBegin.mGroupIndex - 1 ) );
-
- if( ( textInfoIndicesBegin.mWordIndex + 1 < groupLayout.mWordsLayoutInfo.size() ) || ( 0 == textInfoIndicesBegin.mCharacterIndex ) )
- {
- // Remove extra words within current group of words. (and current word if whole characters are removed)
- // 0 == characterIndexBegin means the whole word is deleted.
- const std::size_t wordIndex = ( ( 0 == textInfoIndicesBegin.mCharacterIndex ) ? textInfoIndicesBegin.mWordIndex : textInfoIndicesBegin.mWordIndex + 1 );
-
- // Store text-actors before removing them.
- CollectTextActorsFromWords( removedTextActorsFromBegin, groupLayout, wordIndex, groupLayout.mWordsLayoutInfo.size() );
-
- RemoveWordsFromWordGroup( wordIndex,
- groupLayout.mWordsLayoutInfo.size() - wordIndex,
- groupLayout );
- }
-
- if( ( textInfoIndicesBegin.mWordIndex < groupLayout.mWordsLayoutInfo.size() ) && ( textInfoIndicesBegin.mCharacterIndex > 0 ) )
- {
- // Only some characters of the word need to be removed.
- WordLayoutInfo& wordLayout( *( groupLayout.mWordsLayoutInfo.begin() + textInfoIndicesBegin.mWordIndex ) );
-
- // Store text-actors before removing them.
- CollectTextActors( removedTextActorsFromBegin, wordLayout, textInfoIndicesBegin.mCharacterIndex, wordLayout.mCharactersLayoutInfo.size() );
-
- RemoveCharactersFromWord( textInfoIndicesBegin.mCharacterIndex,
- wordLayout.mCharactersLayoutInfo.size() - textInfoIndicesBegin.mCharacterIndex,
- wordLayout );
- }
- }
-
- if( splitLastGroup )
- {
- // Some characters from the last group of words need to be removed.
-
- // textInfoIndicesEnd.mGroupIndex was increased to delete the last group of words if groups need to be merged.
- // To access now the last group of words we need to decrease the index.
- std::size_t index = mergeGroups ? textInfoIndicesEnd.mGroupIndex - 1 : textInfoIndicesEnd.mGroupIndex;
-
- // Get the last group of words.
- WordGroupLayoutInfo& groupLayout( *( lineLayout.mWordGroupsLayoutInfo.begin() + index ) );
-
- // Check if is needed remove the whole word. (If the character index is pointing just after the end of the word)
- const WordLayoutInfo& wordLayout( *( groupLayout.mWordsLayoutInfo.begin() + textInfoIndicesEnd.mWordIndex ) );
- bool removeWholeWord = wordLayout.mCharactersLayoutInfo.size() == textInfoIndicesEnd.mCharacterIndex + 1;
-
- if( ( textInfoIndicesEnd.mWordIndex > 0 ) || ( removeWholeWord ) )
- {
- // Store text-actors before removing them.
- CollectTextActorsFromWords( removedTextActorsFromBegin, groupLayout, 0, ( removeWholeWord ) ? textInfoIndicesEnd.mWordIndex + 1 : textInfoIndicesEnd.mWordIndex );
-
- // Remove extra words. (and current word if whole characters are removed)
- RemoveWordsFromWordGroup( 0,
- ( removeWholeWord ) ? textInfoIndicesEnd.mWordIndex + 1 : textInfoIndicesEnd.mWordIndex,
- groupLayout );
- }