use of com.intellij.diff.fragments.LineFragment in project intellij-community by JetBrains.
the class SvnPropertiesDiffViewer method setupHighlighting.
private void setupHighlighting(@NotNull DiffChange change, @NotNull Side side) {
PropertyRecord record = change.getRecord();
List<? extends LineFragment> fragments = change.getFragments();
assert fragments != null;
EditorEx editor = getEditor(side);
DocumentEx document = editor.getDocument();
int changeStartLine = change.getStartLine(side);
for (LineFragment fragment : fragments) {
List<DiffFragment> innerFragments = fragment.getInnerFragments();
int startLine = side.getStartLine(fragment) + changeStartLine;
int endLine = side.getEndLine(fragment) + changeStartLine;
int start = document.getLineStartOffset(startLine);
TextDiffType type = DiffUtil.getLineDiffType(fragment);
DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, innerFragments != null);
// TODO: we can paint LineMarker here, but it looks ugly for small editors
if (innerFragments != null) {
for (DiffFragment innerFragment : innerFragments) {
int innerStart = side.getStartOffset(innerFragment);
int innerEnd = side.getEndOffset(innerFragment);
TextDiffType innerType = DiffUtil.getDiffType(innerFragment);
innerStart += start;
innerEnd += start;
DiffDrawUtil.createInlineHighlighter(editor, innerStart, innerEnd, innerType);
}
}
}
}
use of com.intellij.diff.fragments.LineFragment in project intellij-community by JetBrains.
the class UnifiedDiffViewer method performRediff.
@Override
@NotNull
protected Runnable performRediff(@NotNull final ProgressIndicator indicator) {
try {
indicator.checkCanceled();
final Document document1 = getContent1().getDocument();
final Document document2 = getContent2().getDocument();
final CharSequence[] texts = ReadAction.compute(() -> {
return new CharSequence[] { document1.getImmutableCharSequence(), document2.getImmutableCharSequence() };
});
final List<LineFragment> fragments = myTextDiffProvider.compare(texts[0], texts[1], indicator);
final DocumentContent content1 = getContent1();
final DocumentContent content2 = getContent2();
indicator.checkCanceled();
TwosideDocumentData data = ReadAction.compute(() -> {
indicator.checkCanceled();
UnifiedFragmentBuilder builder = new UnifiedFragmentBuilder(fragments, document1, document2, myMasterSide);
builder.exec();
indicator.checkCanceled();
EditorHighlighter highlighter = buildHighlighter(myProject, content1, content2, texts[0], texts[1], builder.getRanges(), builder.getText().length());
UnifiedEditorRangeHighlighter rangeHighlighter = new UnifiedEditorRangeHighlighter(myProject, document1, document2, builder.getRanges());
return new TwosideDocumentData(builder, highlighter, rangeHighlighter);
});
UnifiedFragmentBuilder builder = data.getBuilder();
FileType fileType = content2.getContentType() == null ? content1.getContentType() : content2.getContentType();
LineNumberConvertor convertor1 = builder.getConvertor1();
LineNumberConvertor convertor2 = builder.getConvertor2();
List<LineRange> changedLines = builder.getChangedLines();
boolean isContentsEqual = builder.isEqual();
CombinedEditorData editorData = new CombinedEditorData(builder.getText(), data.getHighlighter(), data.getRangeHighlighter(), fileType, convertor1.createConvertor(), convertor2.createConvertor());
return apply(editorData, builder.getBlocks(), convertor1, convertor2, changedLines, isContentsEqual);
} catch (DiffTooBigException e) {
return () -> {
clearDiffPresentation();
myPanel.setTooBigContent();
};
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable e) {
LOG.error(e);
return () -> {
clearDiffPresentation();
myPanel.setErrorContent();
};
}
}
use of com.intellij.diff.fragments.LineFragment in project intellij-community by JetBrains.
the class ChangesDiffCalculator method calculateDiff.
public static List<TextRange> calculateDiff(@NotNull Document beforeDocument, @NotNull Document currentDocument) {
CharSequence beforeText = beforeDocument.getCharsSequence();
CharSequence currentText = currentDocument.getCharsSequence();
try {
ComparisonManager manager = ComparisonManager.getInstance();
List<LineFragment> lineFragments = manager.compareLinesInner(beforeText, currentText, ComparisonPolicy.DEFAULT, DumbProgressIndicator.INSTANCE);
List<TextRange> modifiedRanges = new ArrayList<>();
for (LineFragment lineFragment : lineFragments) {
int fragmentStartOffset = lineFragment.getStartOffset2();
int fragmentEndOffset = lineFragment.getEndOffset2();
List<DiffFragment> innerFragments = lineFragment.getInnerFragments();
if (innerFragments != null) {
for (DiffFragment innerFragment : innerFragments) {
int innerFragmentStartOffset = fragmentStartOffset + innerFragment.getStartOffset2();
int innerFragmentEndOffset = fragmentStartOffset + innerFragment.getEndOffset2();
modifiedRanges.add(calculateChangeHighlightRange(currentText, innerFragmentStartOffset, innerFragmentEndOffset));
}
} else {
modifiedRanges.add(calculateChangeHighlightRange(currentText, fragmentStartOffset, fragmentEndOffset));
}
}
return modifiedRanges;
} catch (DiffTooBigException e) {
LOG.info(e);
return Collections.emptyList();
}
}
use of com.intellij.diff.fragments.LineFragment in project intellij-community by JetBrains.
the class TwosideTextDiffProviderBase method compare.
@Nullable
@Override
public List<LineFragment> compare(@NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull ProgressIndicator indicator) {
IgnorePolicy ignorePolicy = getIgnorePolicy();
HighlightPolicy highlightPolicy = getHighlightPolicy();
if (!highlightPolicy.isShouldCompare())
return null;
ComparisonPolicy policy = ignorePolicy.getComparisonPolicy();
boolean innerFragments = highlightPolicy.isFineFragments();
boolean squashFragments = highlightPolicy.isShouldSquash();
boolean trimFragments = ignorePolicy.isShouldTrimChunks();
indicator.checkCanceled();
List<LineFragment> fragments = doCompare(text1, text2, ignorePolicy, innerFragments, indicator);
indicator.checkCanceled();
return ComparisonManager.getInstance().processBlocks(fragments, text1, text2, policy, squashFragments, trimFragments);
}
use of com.intellij.diff.fragments.LineFragment in project android by JetBrains.
the class ParcelableQuickFixTest method lineDiff.
private static String lineDiff(String actual, String expected) {
List<LineFragment> fragments = myComparisonManager.compareLines(actual, expected, ComparisonPolicy.DEFAULT, INDICATOR);
if (fragments.isEmpty()) {
return "";
}
StringBuilder diff = new StringBuilder();
diff.append("\n");
for (LineFragment fragment : fragments) {
diff.append(String.format("Expected in line: %s >>>\n", fragment.getStartLine2()));
diff.append(expected.substring(fragment.getStartOffset2(), fragment.getEndOffset2()));
diff.append("Actual: >>>\n");
diff.append(actual.substring(fragment.getStartOffset1(), fragment.getEndOffset1()));
diff.append(">>>\n\n");
}
return diff.toString();
}
Aggregations