com.intellij.openapi.editor.highlighter.HighlighterIterator Java Examples
The following examples show how to use
com.intellij.openapi.editor.highlighter.HighlighterIterator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BraceHighlighter.java From HighlightBracketPair with Apache License 2.0 | 6 votes |
public BracePair findClosetBracePairInBraceTokens(int offset) { EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter(); boolean isBlockCaret = this.isBlockCaret(); List<Pair<IElementType, IElementType>> braceTokens = this.getSupportedBraceToken(); for (Pair<IElementType, IElementType> braceTokenPair : braceTokens) { HighlighterIterator leftTraverseIterator = editorHighlighter.createIterator(offset); HighlighterIterator rightTraverseIterator = editorHighlighter.createIterator(offset); int leftBraceOffset = BraceMatchingUtilAdapter.findLeftLParen( leftTraverseIterator, braceTokenPair.getLeft(), this.fileText, this.fileType, isBlockCaret); int rightBraceOffset = BraceMatchingUtilAdapter.findRightRParen( rightTraverseIterator, braceTokenPair.getRight(), this.fileText, this.fileType, isBlockCaret); if (leftBraceOffset != NON_OFFSET && rightBraceOffset != NON_OFFSET) { return new BracePair.BracePairBuilder(). leftType(braceTokenPair.getLeft()). rightType(braceTokenPair.getRight()). leftIterator(leftTraverseIterator). rightIterator(rightTraverseIterator).build(); } } return EMPTY_BRACE_PAIR; }
Example #2
Source File: CSharpQuoteHandler.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Override public boolean isClosingQuote(HighlighterIterator iterator, int offset) { boolean closingQuote = super.isClosingQuote(iterator, offset); if(closingQuote) { // check escape next if(!iterator.atEnd()) { iterator.advance(); if(!iterator.atEnd() && StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(iterator.getTokenType())) { closingQuote = false; } iterator.retreat(); } } return closingQuote; }
Example #3
Source File: SelectWordAtCaretAction.java From consulo with Apache License 2.0 | 6 votes |
private static void selectWithGuide(Editor editor, IndentGuideDescriptor guide) { final Document doc = editor.getDocument(); int startOffset = editor.logicalPositionToOffset(new LogicalPosition(guide.startLine, 0)); int endOffset = guide.endLine >= doc.getLineCount() ? doc.getTextLength() : doc.getLineStartOffset(guide.endLine); final VirtualFile file = ((EditorEx)editor).getVirtualFile(); if (file != null) { // Make sure selection contains closing matching brace. final CharSequence chars = doc.getCharsSequence(); int nonWhitespaceOffset = CharArrayUtil.shiftForward(chars, endOffset, " \t\n"); HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(nonWhitespaceOffset); if (BraceMatchingUtil.isRBraceToken(iterator, chars, file.getFileType())) { if (editor.offsetToLogicalPosition(iterator.getStart()).column == guide.indentLevel) { endOffset = iterator.getEnd(); endOffset = CharArrayUtil.shiftForward(chars, endOffset, " \t"); if (endOffset < chars.length() && chars.charAt(endOffset) == '\n') endOffset++; } } } editor.getSelectionModel().setSelection(startOffset, endOffset); }
Example #4
Source File: BuildQuoteHandler.java From intellij with Apache License 2.0 | 6 votes |
@Override protected boolean isNonClosedLiteral(HighlighterIterator iterator, CharSequence chars) { int end = iterator.getEnd(); if (getLiteralStartOffset(chars, iterator.getStart()) >= end - 1) { return true; } char endSymbol = chars.charAt(end - 1); if (endSymbol != '"' && endSymbol != '\'') { return true; } //for triple quoted string if (end >= 3 && (endSymbol == chars.charAt(end - 2)) && (chars.charAt(end - 2) == chars.charAt(end - 3)) && (end < 4 || chars.charAt(end - 4) != endSymbol)) { return true; } return false; }
Example #5
Source File: BuildQuoteHandler.java From intellij with Apache License 2.0 | 6 votes |
@Override public boolean isOpeningQuote(HighlighterIterator iterator, int offset) { if (!myLiteralTokenSet.contains(iterator.getTokenType())) { return false; } int start = iterator.getStart(); if (offset == start) { return true; } final Document document = iterator.getDocument(); if (document == null) { return false; } CharSequence text = document.getCharsSequence(); char theQuote = text.charAt(offset); if (offset >= 2 && text.charAt(offset - 1) == theQuote && text.charAt(offset - 2) == theQuote && (offset < 3 || text.charAt(offset - 3) != theQuote)) { if (super.isOpeningQuote(iterator, offset)) { return true; } } return false; }
Example #6
Source File: HTMLTextPainter.java From consulo with Apache License 2.0 | 6 votes |
private void writeStyles(@NonNls final Writer writer) throws IOException { writer.write("<style type=\"text/css\">\n"); writer.write(".ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }\n"); HighlighterIterator hIterator = myHighlighter.createIterator(myOffset); while(!hIterator.atEnd()) { TextAttributes textAttributes = hIterator.getTextAttributes(); if (!myStyleMap.containsKey(textAttributes)) { @NonNls String styleName = "s" + myStyleMap.size(); myStyleMap.put(textAttributes, styleName); writer.write("." + styleName + " { "); final Color foreColor = textAttributes.getForegroundColor(); if (foreColor != null) { writer.write("color: rgb(" + foreColor.getRed() + "," + foreColor.getGreen() + "," + foreColor.getBlue() + "); "); } if ((textAttributes.getFontType() & Font.BOLD) != 0) { writer.write("font-weight: bold; "); } if ((textAttributes.getFontType() & Font.ITALIC) != 0) { writer.write("font-style: italic; "); } writer.write("}\n"); } hIterator.advance(); } writer.write("</style>\n"); }
Example #7
Source File: FilteredIndentsHighlightingPass.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int findCodeConstructStartLine(int startLine) { DocumentEx document = myEditor.getDocument(); CharSequence text = document.getImmutableCharSequence(); int lineStartOffset = document.getLineStartOffset(startLine); int firstNonWsOffset = CharArrayUtil.shiftForward(text, lineStartOffset, " \t"); FileType type = PsiUtilBase.getPsiFileAtOffset(myFile, firstNonWsOffset).getFileType(); Language language = PsiUtilCore.getLanguageAtOffset(myFile, firstNonWsOffset); BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(type, language); HighlighterIterator iterator = myEditor.getHighlighter().createIterator(firstNonWsOffset); if (braceMatcher.isLBraceToken(iterator, text, type)) { int codeConstructStart = braceMatcher.getCodeConstructStart(myFile, firstNonWsOffset); return document.getLineNumber(codeConstructStart); } else { return startLine; } }
Example #8
Source File: FluidQuoteHandler.java From idea-php-typo3-plugin with MIT License | 6 votes |
public boolean hasNonClosedLiteral(@NotNull Editor editor, @NotNull HighlighterIterator iterator, int offset) { Document document = editor.getDocument(); int lineEndOffset = document.getLineEndOffset(document.getLineNumber(offset)); if (offset < lineEndOffset) { CharSequence charSequence = document.getCharsSequence(); char openQuote = charSequence.charAt(offset); int nextCharOffset = offset + 1; if (nextCharOffset < lineEndOffset && charSequence.charAt(nextCharOffset) == openQuote) { return true; } for (int i = nextCharOffset + 1; i < lineEndOffset; ++i) { if (charSequence.charAt(i) == openQuote) { return false; } } } return true; }
Example #9
Source File: ToggleCaseAction.java From consulo with Apache License 2.0 | 6 votes |
private static String toCase(Editor editor, int startOffset, int endOffset, final boolean lower) { CharSequence text = editor.getDocument().getImmutableCharSequence(); EditorHighlighter highlighter; if (editor instanceof EditorEx) { highlighter = ((EditorEx)editor).getHighlighter(); } else { highlighter = new EmptyEditorHighlighter(null); highlighter.setText(text); } HighlighterIterator iterator = highlighter.createIterator(startOffset); StringBuilder builder = new StringBuilder(endOffset - startOffset); while (!iterator.atEnd()) { int start = trim(iterator.getStart(), startOffset, endOffset); int end = trim(iterator.getEnd(), startOffset, endOffset); CharSequence fragment = text.subSequence(start, end); builder.append(iterator.getTokenType() == VALID_STRING_ESCAPE_TOKEN ? fragment : lower ? fragment.toString().toLowerCase(Locale.getDefault()) : fragment.toString().toUpperCase(Locale.getDefault())); if (end == endOffset) break; iterator.advance(); } return builder.toString(); }
Example #10
Source File: LexerEditorHighlighter.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public HighlighterIterator createIterator(int startOffset) { synchronized (this) { if (!isInSyncWithDocument()) { final Document document = getDocument(); assert document != null; if (document.isInBulkUpdate()) { document.setInBulkUpdate(false); // bulk mode failed } doSetText(document.getImmutableCharSequence()); } final int latestValidOffset = mySegments.getLastValidOffset(); return new HighlighterIteratorImpl(startOffset <= latestValidOffset ? startOffset : latestValidOffset); } }
Example #11
Source File: SimpleEditorPreview.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static String selectItem(HighlighterIterator itr, SyntaxHighlighter highlighter) { IElementType tokenType = itr.getTokenType(); if (tokenType == null) return null; TextAttributesKey[] highlights = highlighter.getTokenHighlights(tokenType); String s = null; for (int i = highlights.length - 1; i >= 0; i--) { if (highlights[i] != HighlighterColors.TEXT) { s = highlights[i].getExternalName(); break; } } return s == null ? HighlighterColors.TEXT.getExternalName() : s; }
Example #12
Source File: BraceHighlightingHandler.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull static EditorHighlighter getLazyParsableHighlighterIfAny(Project project, Editor editor, PsiFile psiFile) { if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) { return ((EditorEx)editor).getHighlighter(); } PsiElement elementAt = psiFile.findElementAt(editor.getCaretModel().getOffset()); for (PsiElement e : SyntaxTraverser.psiApi().parents(elementAt).takeWhile(Conditions.notEqualTo(psiFile))) { if (!(PsiUtilCore.getElementType(e) instanceof ILazyParseableElementType)) continue; Language language = ILazyParseableElementType.LANGUAGE_KEY.get(e.getNode()); if (language == null) continue; TextRange range = e.getTextRange(); final int offset = range.getStartOffset(); SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, psiFile.getVirtualFile()); LexerEditorHighlighter highlighter = new LexerEditorHighlighter(syntaxHighlighter, editor.getColorsScheme()) { @Nonnull @Override public HighlighterIterator createIterator(int startOffset) { return new HighlighterIteratorWrapper(super.createIterator(Math.max(startOffset - offset, 0))) { @Override public int getStart() { return super.getStart() + offset; } @Override public int getEnd() { return super.getEnd() + offset; } }; } }; highlighter.setText(editor.getDocument().getText(range)); return highlighter; } return ((EditorEx)editor).getHighlighter(); }
Example #13
Source File: BraceMatchingUtilAdapter.java From HighlightBracketPair with Apache License 2.0 | 5 votes |
/** * find the right closest brace offset position * * @param iterator highlight iterator * @param rparenTokenType right token type to paired * @param fileText file text * @param fileType file type * @return offset */ public static int findRightRParen(HighlighterIterator iterator, IElementType rparenTokenType, CharSequence fileText, FileType fileType, boolean isBlockCaret) { int lastRbraceOffset = -1; int initOffset = iterator.atEnd() ? -1 : iterator.getStart(); Stack<IElementType> braceStack = new Stack<>(); for (; !iterator.atEnd(); iterator.advance()) { final IElementType tokenType = iterator.getTokenType(); if (isRBraceToken(iterator, fileText, fileType)) { if (!braceStack.isEmpty()) { IElementType topToken = braceStack.pop(); if (!isPairBraces(tokenType, topToken, fileType)) { break; // unmatched braces } } else { if (tokenType == rparenTokenType) { return iterator.getStart(); } else { break; } } } else if (isLBraceToken(iterator, fileText, fileType)) { if (isBlockCaret && initOffset == iterator.getStart()) continue; else braceStack.push(iterator.getTokenType()); } } return lastRbraceOffset; }
Example #14
Source File: TypedHandler.java From consulo with Apache License 2.0 | 5 votes |
private static boolean hasNonClosedLiterals(@Nonnull Editor editor, @Nonnull QuoteHandler quoteHandler, int offset) { HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset); if (iterator.atEnd()) { LOG.assertTrue(false); return false; } return quoteHandler.hasNonClosedLiteral(editor, iterator, offset); }
Example #15
Source File: CSharpDocBraceMatcher.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override public boolean isLBraceToken(HighlighterIterator iterator, CharSequence fileText, FileType fileType) { final IElementType tokenType = iterator.getTokenType(); return tokenType == CSharpDocTokenType.XML_START_TAG_START || tokenType == CSharpDocTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER; }
Example #16
Source File: TypedHandler.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private static CharSequence getClosingQuote(@Nonnull Editor editor, @Nonnull MultiCharQuoteHandler quoteHandler, int offset) { HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset); if (iterator.atEnd()) { LOG.assertTrue(false); return null; } return quoteHandler.getClosingQuote(iterator, offset); }
Example #17
Source File: TypedHandler.java From consulo with Apache License 2.0 | 5 votes |
private static boolean isInsideLiteral(@Nonnull Editor editor, @Nonnull QuoteHandler quoteHandler, int offset) { if (offset == 0) return false; HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset - 1); if (iterator.atEnd()) { LOG.assertTrue(false); return false; } return quoteHandler.isInsideLiteral(iterator); }
Example #18
Source File: BraceHighlightingHandler.java From consulo with Apache License 2.0 | 5 votes |
private void doHighlight(int offset, int originalOffset, @Nonnull FileType fileType) { if (myEditor.getFoldingModel().isOffsetCollapsed(offset)) return; HighlighterIterator iterator = getEditorHighlighter().createIterator(offset); final CharSequence chars = myDocument.getCharsSequence(); if (BraceMatchingUtil.isLBraceToken(iterator, chars, fileType)) { IElementType tokenType = iterator.getTokenType(); iterator.advance(); if (!iterator.atEnd() && BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) { if (BraceMatchingUtil.isPairBraces(tokenType, iterator.getTokenType(), fileType) && originalOffset == iterator.getStart()) return; } iterator.retreat(); highlightLeftBrace(iterator, false, fileType); if (offset > 0) { iterator = getEditorHighlighter().createIterator(offset - 1); if (BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) { highlightRightBrace(iterator, fileType); } } } else if (BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) { highlightRightBrace(iterator, fileType); } }
Example #19
Source File: PairedBraceMatcherAdapter.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isStructuralBrace(HighlighterIterator iterator, CharSequence text, FileType fileType) { final IElementType tokenType = iterator.getTokenType(); final BracePair[] pairs = myMatcher.getPairs(); for (BracePair pair : pairs) { if (tokenType == pair.getRightBraceType() || tokenType == pair.getLeftBraceType()) return pair.isStructural(); } return false; }
Example #20
Source File: CommentByBlockCommentHandler.java From consulo with Apache License 2.0 | 5 votes |
private TextRange getBlockCommentAt(int offset) { CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter)myCommenter; HighlighterIterator it = ((EditorEx)myEditor).getHighlighter().createIterator(offset); if (it.getTokenType() == commenter.getBlockCommentTokenType()) { return new TextRange(it.getStart(), it.getEnd()); } if (docCommentIsBlockComment(commenter)) { PsiComment comment = getCommentAtOffset(offset); if (comment != null && commenter.isDocumentationComment(comment)) { return comment.getTextRange(); } } return null; }
Example #21
Source File: SyntaxHighlighterOverEditorHighlighter.java From consulo with Apache License 2.0 | 5 votes |
public void resetPosition(int startOffset) { if (lexer instanceof LexerEditorHighlighterLexer) { ((LexerEditorHighlighterLexer)lexer).resetPosition(startOffset); HighlighterIterator iterator = ((LexerEditorHighlighterLexer)lexer).getHighlighterIterator(); if (iterator instanceof LayeredHighlighterIterator) { layeredHighlighterIterator = (LayeredHighlighterIterator)iterator; } else { layeredHighlighterIterator = null; } } else { CharSequence text = lexer.getBufferSequence(); lexer.start(text, startOffset, text.length()); } }
Example #22
Source File: XQueryQuoteHandler.java From intellij-xquery with Apache License 2.0 | 5 votes |
@Override public boolean isOpeningQuote(HighlighterIterator iterator, int offset) { if (OPENINGQUOT == iterator.getTokenType() || OPENINGAPOS == iterator.getTokenType()){ int start = iterator.getStart(); return offset == start; } return false; }
Example #23
Source File: SyntaxHighlighterOverEditorHighlighter.java From consulo with Apache License 2.0 | 5 votes |
public void restart(@Nonnull CharSequence text) { lexer.start(text); if (lexer instanceof LexerEditorHighlighterLexer) { HighlighterIterator iterator = ((LexerEditorHighlighterLexer)lexer).getHighlighterIterator(); if (iterator instanceof LayeredHighlighterIterator) { layeredHighlighterIterator = (LayeredHighlighterIterator)iterator; } else { layeredHighlighterIterator = null; } } }
Example #24
Source File: DustEnterHandler.java From Intellij-Dust with MIT License | 5 votes |
/** * Checks to see if {@code Enter} has been typed while the caret is between an open and close tag pair. * @return true if between open and close tags, false otherwise */ private static boolean isBetweenHbTags(Editor editor, PsiFile file, int offset) { if (offset == 0) return false; CharSequence chars = editor.getDocument().getCharsSequence(); if (chars.charAt(offset - 1) != '}') return false; EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter(); HighlighterIterator iterator = highlighter.createIterator(offset - 1); final PsiElement openerElement = file.findElementAt(iterator.getStart()); PsiElement openTag = DustPsiUtil.findParentOpenTagElement(openerElement); if (openTag == null) { return false; } iterator.advance(); if (iterator.atEnd()) { // no more tokens, so certainly no close tag return false; } final PsiElement closerElement = file.findElementAt(iterator.getStart()); PsiElement closeTag = DustPsiUtil.findParentCloseTagElement(closerElement); // if we got this far, we're between open and close tags iff this is a close tag return closeTag != null; }
Example #25
Source File: PairedBraceMatcherAdapter.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public BracePair findPair(boolean left, HighlighterIterator iterator, CharSequence fileText, FileType fileType) { final IElementType tokenType = iterator.getTokenType(); final BracePair[] pairs = myMatcher.getPairs(); for (BracePair pair : pairs) { if (tokenType == (left ? pair.getLeftBraceType() : pair.getRightBraceType())) return pair; } return null; }
Example #26
Source File: EditorPainter.java From consulo with Apache License 2.0 | 5 votes |
private void paintBorderEffect(EditorHighlighter highlighter) { HighlighterIterator it = highlighter.createIterator(myStartOffset); while (!it.atEnd() && it.getStart() < myEndOffset) { TextAttributes attributes = it.getTextAttributes(); EffectDescriptor borderDescriptor = getBorderDescriptor(attributes); if (borderDescriptor != null) { paintBorderEffect(it.getStart(), it.getEnd(), borderDescriptor); } it.advance(); } }
Example #27
Source File: SimpleTokenSetQuoteHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isOpeningQuote(HighlighterIterator iterator, int offset) { if (myLiteralTokenSet.contains(iterator.getTokenType())){ int start = iterator.getStart(); return offset == start; } return false; }
Example #28
Source File: RecentLocationsDataModel.java From consulo with Apache License 2.0 | 5 votes |
private void applySyntaxHighlighting(Project project, EditorEx editor, Document document, EditorColorsScheme colorsScheme, TextRange textRange, IdeDocumentHistoryImpl.PlaceInfo placeInfo) { EditorHighlighter editorHighlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(placeInfo.getFile(), colorsScheme, project); editorHighlighter.setEditor(new LightHighlighterClient(document, project)); editorHighlighter.setText(document.getText(TextRange.create(0, textRange.getEndOffset()))); int startOffset = textRange.getStartOffset(); for (HighlighterIterator iterator = editorHighlighter.createIterator(startOffset); !iterator.atEnd() && iterator.getEnd() <= textRange.getEndOffset(); iterator.advance()) { if (iterator.getStart() >= startOffset) { editor.getMarkupModel().addRangeHighlighter(iterator.getStart() - startOffset, iterator.getEnd() - startOffset, 999, iterator.getTextAttributes(), HighlighterTargetArea.EXACT_RANGE); } } }
Example #29
Source File: CustomFileTypeCompletionContributor.java From consulo with Apache License 2.0 | 5 votes |
private static boolean inCommentOrLiteral(CompletionParameters parameters) { HighlighterIterator iterator = ((EditorEx)parameters.getEditor()).getHighlighter().createIterator(parameters.getOffset()); IElementType elementType = iterator.getTokenType(); if (elementType == CustomHighlighterTokenType.WHITESPACE) { iterator.retreat(); elementType = iterator.getTokenType(); } return elementType == CustomHighlighterTokenType.LINE_COMMENT || elementType == CustomHighlighterTokenType.MULTI_LINE_COMMENT || elementType == CustomHighlighterTokenType.STRING || elementType == CustomHighlighterTokenType.SINGLE_QUOTED_STRING; }
Example #30
Source File: BraceMatcherBasedSelectioner.java From consulo with Apache License 2.0 | 5 votes |
@Override public List<TextRange> select(final PsiElement e, final CharSequence editorText, final int cursorOffset, final Editor editor) { final VirtualFile file = e.getContainingFile().getVirtualFile(); final FileType fileType = file == null? null : file.getFileType(); if (fileType == null) return super.select(e, editorText, cursorOffset, editor); final int textLength = editorText.length(); final TextRange totalRange = e.getTextRange(); final HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(totalRange.getStartOffset()); final BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator); final ArrayList<TextRange> result = new ArrayList<TextRange>(); final LinkedList<Trinity<Integer, Integer, IElementType>> stack = new LinkedList<Trinity<Integer, Integer, IElementType>>(); while (!iterator.atEnd() && iterator.getStart() < totalRange.getEndOffset()) { final Trinity<Integer, Integer, IElementType> last; if (braceMatcher.isLBraceToken(iterator, editorText, fileType)) { stack.addLast(Trinity.create(iterator.getStart(), iterator.getEnd(), iterator.getTokenType())); } else if (braceMatcher.isRBraceToken(iterator, editorText, fileType) && !stack.isEmpty() && braceMatcher.isPairBraces((last = stack.getLast()).third, iterator.getTokenType())) { stack.removeLast(); result.addAll(expandToWholeLine(editorText, new TextRange(last.first, iterator.getEnd()))); int bodyStart = last.second; int bodyEnd = iterator.getStart(); while (bodyStart < textLength && Character.isWhitespace(editorText.charAt(bodyStart))) bodyStart ++; while (bodyEnd > 0 && Character.isWhitespace(editorText.charAt(bodyEnd - 1))) bodyEnd --; result.addAll(expandToWholeLine(editorText, new TextRange(bodyStart, bodyEnd))); } iterator.advance(); } result.add(e.getTextRange()); return result; }