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);
}
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());
}
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;
}
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);
}
Aggregations