protected int getSearchEndIndex ( final @ NonNull Spanned text , int cursor ) { if ( cursor < 0 || cursor > text . length ( ) ) { cursor = 0 ; } // Get index of the start of the first span after the cursor (or text.length() if does not exist) MentionSpan [ ] spans = text . getSpans ( 0 , text . length ( ) , MentionSpan . class ) ; int closestAfterCursor = text . length ( ) ; for ( MentionSpan span : spans ) { int start = text . getSpanStart ( span ) ; if ( start < closestAfterCursor && start >= cursor ) { closestAfterCursor = start ; } } // Get the index of the end of the line String textString = text . toString ( ) . substring ( cursor , text . length ( ) ) ; int lineEndIndex = text . length ( ) ; if ( textString . contains ( mConfig . LINE_SEPARATOR ) ) { lineEndIndex = cursor + textString . indexOf ( mConfig . LINE_SEPARATOR ) ; } // Return whichever is closest after the cursor return Math . min ( closestAfterCursor , lineEndIndex ) ; }
Returns the index of the beginning of the first span after the cursor or length of the text if there are no spans after the cursor .