Search in sources :

Example 1 with MergingCharSequence

use of com.intellij.util.text.MergingCharSequence in project intellij-community by JetBrains.

the class LineSet method genericUpdate.

private LineSet genericUpdate(CharSequence prevText, int _start, int _end, CharSequence replacement) {
    int startOffset = _start;
    if (replacement.length() > 0 && replacement.charAt(0) == '\n' && startOffset > 0 && prevText.charAt(startOffset - 1) == '\r') {
        startOffset--;
    }
    int startLine = findLineIndex(startOffset);
    startOffset = getLineStart(startLine);
    int endOffset = _end;
    if (replacement.length() > 0 && replacement.charAt(replacement.length() - 1) == '\r' && endOffset < prevText.length() && prevText.charAt(endOffset) == '\n') {
        endOffset++;
    }
    int endLine = findLineIndex(endOffset);
    endOffset = getLineEnd(endLine);
    if (!isLastEmptyLine(endLine))
        endLine++;
    replacement = new MergingCharSequence(new MergingCharSequence(prevText.subSequence(startOffset, _start), replacement), prevText.subSequence(_end, endOffset));
    LineSet patch = createLineSet(replacement, true);
    return applyPatch(startOffset, endOffset, startLine, endLine, patch);
}
Also used : MergingCharSequence(com.intellij.util.text.MergingCharSequence)

Example 2 with MergingCharSequence

use of com.intellij.util.text.MergingCharSequence in project intellij-community by JetBrains.

the class LexerEditorHighlighter method getAttributesForPreviousAndTypedChars.

@NotNull
public List<TextAttributes> getAttributesForPreviousAndTypedChars(@NotNull Document document, int offset, char c) {
    final CharSequence text = document.getImmutableCharSequence();
    final CharSequence newText = new MergingCharSequence(new MergingCharSequence(text.subSequence(0, offset), new SingleCharSequence(c)), text.subSequence(offset, text.length()));
    final List<IElementType> tokenTypes = getTokenType(newText, offset);
    return Arrays.asList(getAttributes(tokenTypes.get(0)).clone(), getAttributes(tokenTypes.get(1)).clone());
}
Also used : SingleCharSequence(com.intellij.util.text.SingleCharSequence) IElementType(com.intellij.psi.tree.IElementType) SingleCharSequence(com.intellij.util.text.SingleCharSequence) MergingCharSequence(com.intellij.util.text.MergingCharSequence) ImmutableCharSequence(com.intellij.util.text.ImmutableCharSequence) MergingCharSequence(com.intellij.util.text.MergingCharSequence) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MergingCharSequence

use of com.intellij.util.text.MergingCharSequence in project intellij-community by JetBrains.

the class LineSet method update.

@NotNull
LineSet update(@NotNull CharSequence prevText, int start, int end, @NotNull CharSequence replacement, boolean wholeTextReplaced) {
    if (myLength == 0) {
        return createLineSet(replacement, !wholeTextReplaced);
    }
    LineSet result = isSingleLineChange(start, end, replacement) ? updateInsideOneLine(findLineIndex(start), replacement.length() - (end - start)) : genericUpdate(prevText, start, end, replacement);
    if (doTest) {
        MergingCharSequence newText = new MergingCharSequence(new MergingCharSequence(prevText.subSequence(0, start), replacement), prevText.subSequence(end, prevText.length()));
        result.checkEquals(createLineSet(newText));
    }
    return wholeTextReplaced ? result.clearModificationFlags() : result;
}
Also used : MergingCharSequence(com.intellij.util.text.MergingCharSequence) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with MergingCharSequence

use of com.intellij.util.text.MergingCharSequence in project intellij-community by JetBrains.

the class ByWord method comparePunctuation2Side.

/*
   * Compare one char sequence with two others (as if they were single sequence)
   *
   * Return two DiffIterable: (0, len1) - (0, len21) and (0, len1) - (0, len22)
   */
@NotNull
private static Couple<FairDiffIterable> comparePunctuation2Side(@NotNull CharSequence text1, @NotNull CharSequence text21, @NotNull CharSequence text22, @NotNull ProgressIndicator indicator) {
    CharSequence text2 = new MergingCharSequence(text21, text22);
    FairDiffIterable changes = ByChar.comparePunctuation(text1, text2, indicator);
    Couple<List<Range>> ranges = splitIterable2Side(changes, text21.length());
    FairDiffIterable iterable1 = fair(createUnchanged(ranges.first, text1.length(), text21.length()));
    FairDiffIterable iterable2 = fair(createUnchanged(ranges.second, text1.length(), text22.length()));
    return Couple.of(iterable1, iterable2);
}
Also used : MergingCharSequence(com.intellij.util.text.MergingCharSequence) MergingCharSequence(com.intellij.util.text.MergingCharSequence) FairDiffIterable(com.intellij.diff.comparison.iterables.FairDiffIterable) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MergingCharSequence (com.intellij.util.text.MergingCharSequence)4 NotNull (org.jetbrains.annotations.NotNull)3 FairDiffIterable (com.intellij.diff.comparison.iterables.FairDiffIterable)1 IElementType (com.intellij.psi.tree.IElementType)1 ImmutableCharSequence (com.intellij.util.text.ImmutableCharSequence)1 SingleCharSequence (com.intellij.util.text.SingleCharSequence)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1