/** * * @param highlighterIterator * @param offset the current offset in the file of the {@code highlighterIterator} * @return {@code true} if {@link HighlighterIterator#getTokenType()} is one of {@link #CLOSING_QUOTES} and * {@code offset} is {@link HighlighterIterator#getStart()} */ @Override public boolean isClosingQuote(HighlighterIterator highlighterIterator, int offset) { boolean isClosingQuote = false; if (CLOSING_QUOTES.contains(highlighterIterator.getTokenType())) { int start = highlighterIterator.getStart(); int end = highlighterIterator.getEnd(); isClosingQuote = end - start >= 1 && offset == end - 1; } return isClosingQuote; }
@Nullable @Override public CharSequence getClosingQuote(HighlighterIterator highlighterIterator, int offset) { CharSequence closingQuote = null; if (highlighterIterator.getStart() > 0) { highlighterIterator.retreat(); try { IElementType tokenType = highlighterIterator.getTokenType(); if (CLOSING_QUOTE_BY_OPENING_QUOTE.get(tokenType) != null) { Document document = highlighterIterator.getDocument(); if (document != null) { String promoter = document.getText( new TextRange(highlighterIterator.getStart(), highlighterIterator.getEnd()) ); String terminator = StackFrame.TERMINATOR_BY_PROMOTER.get(promoter); if (terminator != null) { if (terminator.length() >= 3) { closingQuote = "\n" + terminator; } else { closingQuote = terminator; } } } } } finally { highlighterIterator.advance(); } } return closingQuote; }
/** * Should return true if the current offset is the closing quote of the string. Unfortunately, I'm not quite sure * anymore why I had to make the calculations but I remember that something with the removal of an empty string did * not work. * * @param iterator * the iterator to move through the token stream. Here, only used to get the current token type * @param offset * current character offset * @return true, if the current offset is a closing quote */ @Override public boolean isClosingQuote(HighlighterIterator iterator, int offset) { final IElementType tokenType = iterator.getTokenType(); if (tokenType.equals(STRING_LITERAL_END)) { int start = iterator.getStart(); int end = iterator.getEnd(); return end - start >= 1 && offset == end - 1; } return false; }
@Nullable private IElementType getNonWhitespaceElementType(final HighlighterIterator iterator, int curLineStart, final int prevLineStartOffset) { while (!iterator.atEnd() && iterator.getEnd() >= curLineStart && iterator.getStart() >= prevLineStartOffset) { final IElementType tokenType = iterator.getTokenType(); if (!MathematicaElementTypes.WHITE_SPACE_OR_COMMENTS.contains(tokenType)) { return tokenType; } iterator.retreat(); } return null; }
@Nullable private IElementType getNonWhitespaceElementType(final HighlighterIterator iterator, int curLineStart, final int prevLineStartOffset) { while (!iterator.atEnd() && iterator.getEnd() >= curLineStart && iterator.getStart() >= prevLineStartOffset) { final IElementType tokenType = iterator.getTokenType(); if (!MathematicaElementTypes.WHITE_SPACE_OR_COMMENTS.contains(tokenType)) { return tokenType; } iterator.retreat(); } return null; }
return false; else if (level == 0 && highlighterIterator.getEnd() > offset) { return true;
public Brace(IElementType elementType, HighlighterIterator iterator) { this.elementType = elementType; this.offset = iterator.getStart(); Document document = iterator.getDocument(); this.text = document.getText(new TextRange(iterator.getStart(), iterator.getEnd())); }
StringUtil.containsLineBreak(documentChars.subSequence(currentOffset, highlighterIterator.getEnd()))) { return Result.Continue;
PerlEditorUtil.moveToPreviousMeaningfulToken(highlighter.createIterator(currentOffset - 1)); if (!preQuoteIterator.atEnd() && QUOTE_OPEN_ANY.contains(preQuoteIterator.getTokenType())) { startOffsetToDelete = preQuoteIterator.getEnd(); caretModel.moveToOffset(preQuoteIterator.getEnd()); POST_HANDLER.set(editor, () -> true); editor.getDocument().deleteString(startOffsetToDelete, iterator.getEnd());
public BracePair findClosetBracePairInStringSymbols(int offset) { if (offset < 0 || this.fileText == null || this.fileText.length() == 0) return EMPTY_BRACE_PAIR; EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter(); HighlighterIterator iterator = editorHighlighter.createIterator(offset); IElementType type = iterator.getTokenType(); boolean isBlockCaret = this.isBlockCaret(); if (!BraceMatchingUtilAdapter.isStringToken(type)) return EMPTY_BRACE_PAIR; int leftOffset = iterator.getStart(); int rightOffset = iterator.getEnd() - 1; if (!isBlockCaret && leftOffset == offset) return EMPTY_BRACE_PAIR; return new BracePair.BracePairBuilder(). leftType(DOUBLE_QUOTE). rightType(DOUBLE_QUOTE). leftOffset(leftOffset). rightOffset(rightOffset).build(); }