use of com.intellij.diff.fragments.DiffFragment 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.DiffFragment 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.DiffFragment in project intellij-community by JetBrains.
the class LineStatusMarkerPopup method createEditorComponent.
@Nullable
private EditorFragmentComponent createEditorComponent(@Nullable FileType fileType, @Nullable List<DiffFragment> wordDiff) {
if (myRange.getType() == Range.INSERTED)
return null;
EditorEx uEditor = (EditorEx) EditorFactory.getInstance().createViewer(myTracker.getVcsDocument(), myTracker.getProject());
uEditor.setColorsScheme(myEditor.getColorsScheme());
DiffUtil.setEditorCodeStyle(myTracker.getProject(), uEditor, fileType);
EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
uEditor.setHighlighter(highlighterFactory.createEditorHighlighter(myTracker.getProject(), getFileName(myTracker.getDocument())));
if (wordDiff != null) {
int vcsStartShift = myTracker.getVcsTextRange(myRange).getStartOffset();
for (DiffFragment fragment : wordDiff) {
int vcsStart = vcsStartShift + fragment.getStartOffset1();
int vcsEnd = vcsStartShift + fragment.getEndOffset1();
TextDiffType type = getDiffType(fragment);
DiffDrawUtil.createInlineHighlighter(uEditor, vcsStart, vcsEnd, type);
}
}
EditorFragmentComponent fragmentComponent = EditorFragmentComponent.createEditorFragmentComponent(myEditor.getContentComponent(), uEditor, myRange.getVcsLine1(), myRange.getVcsLine2(), false, false);
EditorFactory.getInstance().releaseEditor(uEditor);
return fragmentComponent;
}
use of com.intellij.diff.fragments.DiffFragment in project intellij-community by JetBrains.
the class SimpleDiffChange method doInstallHighlighterWithInner.
private void doInstallHighlighterWithInner() {
assert myInnerFragments != null;
createHighlighter(Side.LEFT, true);
createHighlighter(Side.RIGHT, true);
for (DiffFragment fragment : myInnerFragments) {
createInlineHighlighter(fragment, Side.LEFT);
createInlineHighlighter(fragment, Side.RIGHT);
}
}
use of com.intellij.diff.fragments.DiffFragment in project intellij-community by JetBrains.
the class ByWord method compareAndSplit.
@NotNull
public static List<LineBlock> compareAndSplit(@NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull ComparisonPolicy policy, @NotNull ProgressIndicator indicator) {
indicator.checkCanceled();
// TODO: figure out, what do we exactly want from 'Split' logic
// -- it is used for trimming of ignored blocks. So we want whitespace-only leading/trailing lines to be separate block.
// -- old approach: split by matched '\n's
// TODO: other approach could lead to better results:
// * Compare words-only
// * prefer big chunks
// -- here we can try to minimize number of matched pairs 'pair[i]' and 'pair[i+1]' such that
// containsNewline(pair[i].left .. pair[i+1].left) XOR containsNewline(pair[i].right .. pair[i+1].right) == true
// ex: "A X C" - "A Y C \n M C" - do not match with last 'C'
// ex: "A \n" - "A B \n \n" - do not match with last '\n'
// Try some greedy approach ?
// * split into blocks
// -- squash blocks with too small unchanged words count (1 matched word out of 40 - is a bad reason to create new block)
// * match adjustment punctuation
// * match adjustment whitespaces ('\n' are matched here)
List<InlineChunk> words1 = getInlineChunks(text1);
List<InlineChunk> words2 = getInlineChunks(text2);
FairDiffIterable wordChanges = diff(words1, words2, indicator);
wordChanges = optimizeWordChunks(text1, text2, words1, words2, wordChanges, indicator);
List<WordBlock> wordBlocks = new LineFragmentSplitter(text1, text2, words1, words2, wordChanges, indicator).run();
List<LineBlock> lineBlocks = new ArrayList<>(wordBlocks.size());
for (WordBlock block : wordBlocks) {
Range offsets = block.offsets;
Range words = block.words;
CharSequence subtext1 = text1.subSequence(offsets.start1, offsets.end1);
CharSequence subtext2 = text2.subSequence(offsets.start2, offsets.end2);
List<InlineChunk> subwords1 = words1.subList(words.start1, words.end1);
List<InlineChunk> subwords2 = words2.subList(words.start2, words.end2);
FairDiffIterable subiterable = fair(subiterable(wordChanges, words.start1, words.end1, words.start2, words.end2));
FairDiffIterable delimitersIterable = matchAdjustmentDelimiters(subtext1, subtext2, subwords1, subwords2, subiterable, offsets.start1, offsets.start2, indicator);
DiffIterable iterable = matchAdjustmentWhitespaces(subtext1, subtext2, delimitersIterable, policy, indicator);
List<DiffFragment> fragments = convertIntoDiffFragments(iterable);
int newlines1 = countNewlines(subwords1);
int newlines2 = countNewlines(subwords2);
lineBlocks.add(new LineBlock(fragments, offsets, newlines1, newlines2));
}
return lineBlocks;
}
Aggregations