use of com.intellij.diff.fragments.DiffFragment in project intellij-community by JetBrains.
the class DiffDrawUtil method createUnifiedChunkHighlighters.
//
// Highlighters
//
// TODO: desync of range and 'border' line markers on typing
@NotNull
public static List<RangeHighlighter> createUnifiedChunkHighlighters(@NotNull Editor editor, @NotNull LineRange deleted, @NotNull LineRange inserted, @Nullable List<DiffFragment> innerFragments) {
boolean ignored = innerFragments != null;
List<RangeHighlighter> list = new ArrayList<>();
if (!inserted.isEmpty() && !deleted.isEmpty()) {
list.addAll(createHighlighter(editor, deleted.start, deleted.end, TextDiffType.DELETED, ignored));
list.addAll(createHighlighter(editor, inserted.start, inserted.end, TextDiffType.INSERTED, ignored));
} else if (!inserted.isEmpty()) {
list.addAll(createHighlighter(editor, inserted.start, inserted.end, TextDiffType.INSERTED, ignored));
} else if (!deleted.isEmpty()) {
list.addAll(createHighlighter(editor, deleted.start, deleted.end, TextDiffType.DELETED, ignored));
}
if (innerFragments != null) {
int deletedStartOffset = editor.getDocument().getLineStartOffset(deleted.start);
int insertedStartOffset = editor.getDocument().getLineStartOffset(inserted.start);
for (DiffFragment fragment : innerFragments) {
int deletedWordStart = deletedStartOffset + fragment.getStartOffset1();
int deletedWordEnd = deletedStartOffset + fragment.getEndOffset1();
list.addAll(createInlineHighlighter(editor, deletedWordStart, deletedWordEnd, TextDiffType.DELETED));
int insertedWordStart = insertedStartOffset + fragment.getStartOffset2();
int insertedWordEnd = insertedStartOffset + fragment.getEndOffset2();
list.addAll(createInlineHighlighter(editor, insertedWordStart, insertedWordEnd, TextDiffType.INSERTED));
}
}
return list;
}
use of com.intellij.diff.fragments.DiffFragment in project intellij-community by JetBrains.
the class LineStatusMarkerPopup method showHintAt.
public void showHintAt(@Nullable Point mousePosition) {
if (!myTracker.isValid())
return;
final Disposable disposable = Disposer.newDisposable();
FileType fileType = getFileType();
List<DiffFragment> wordDiff = computeWordDiff();
installMasterEditorHighlighters(wordDiff, disposable);
JComponent editorComponent = createEditorComponent(fileType, wordDiff);
ActionToolbar toolbar = buildToolbar(mousePosition, disposable);
// we need valid ActionToolbar.getPreferredSize() to calc size of popup
toolbar.updateActionsImmediately();
toolbar.setReservePlaceAutoPopupIcon(false);
PopupPanel popupPanel = new PopupPanel(myEditor, toolbar, editorComponent);
LightweightHint hint = new LightweightHint(popupPanel);
HintListener closeListener = new HintListener() {
public void hintHidden(final EventObject event) {
Disposer.dispose(disposable);
}
};
hint.addHintListener(closeListener);
int line = myEditor.getCaretModel().getLogicalPosition().line;
Point point = HintManagerImpl.getHintPosition(hint, myEditor, new LogicalPosition(line, 0), HintManager.UNDER);
if (mousePosition != null) {
// show right after the nearest line
int lineHeight = myEditor.getLineHeight();
int delta = (point.y - mousePosition.y) % lineHeight;
if (delta < 0)
delta += lineHeight;
point.y = mousePosition.y + delta;
}
// align main editor with the one in popup
point.x -= popupPanel.getEditorTextOffset();
int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING;
HintManagerImpl.getInstanceImpl().showEditorHint(hint, myEditor, point, flags, -1, false, new HintHint(myEditor, point));
if (!hint.isVisible()) {
closeListener.hintHidden(null);
}
}
use of com.intellij.diff.fragments.DiffFragment in project intellij-community by JetBrains.
the class LineStatusMarkerPopup method installMasterEditorHighlighters.
private void installMasterEditorHighlighters(@Nullable List<DiffFragment> wordDiff, @NotNull Disposable parentDisposable) {
if (wordDiff == null)
return;
final List<RangeHighlighter> highlighters = new ArrayList<>();
int currentStartShift = myTracker.getCurrentTextRange(myRange).getStartOffset();
for (DiffFragment fragment : wordDiff) {
int currentStart = currentStartShift + fragment.getStartOffset2();
int currentEnd = currentStartShift + fragment.getEndOffset2();
TextDiffType type = getDiffType(fragment);
highlighters.addAll(DiffDrawUtil.createInlineHighlighter(myEditor, currentStart, currentEnd, type));
}
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
for (RangeHighlighter highlighter : highlighters) {
highlighter.dispose();
}
}
});
}
use of com.intellij.diff.fragments.DiffFragment in project intellij-community by JetBrains.
the class DiffUtil method compareThreesideInner.
@Nullable
public static MergeInnerDifferences compareThreesideInner(@NotNull List<CharSequence> chunks, @NotNull ComparisonPolicy comparisonPolicy, @NotNull ProgressIndicator indicator) {
// ---
if (chunks.get(0) == null && chunks.get(1) == null && chunks.get(2) == null)
return null;
if (comparisonPolicy == ComparisonPolicy.IGNORE_WHITESPACES) {
if (isChunksEquals(chunks.get(0), chunks.get(1), comparisonPolicy) && isChunksEquals(chunks.get(0), chunks.get(2), comparisonPolicy)) {
// whitespace-only changes, ex: empty lines added/removed
return new MergeInnerDifferences(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
}
}
if (chunks.get(0) == null && chunks.get(1) == null || chunks.get(0) == null && chunks.get(2) == null || chunks.get(1) == null && chunks.get(2) == null) {
// =--, -=-, --=
return null;
}
if (chunks.get(0) != null && chunks.get(1) != null && chunks.get(2) != null) {
// ===
List<DiffFragment> fragments1 = ByWord.compare(chunks.get(1), chunks.get(0), comparisonPolicy, indicator);
List<DiffFragment> fragments2 = ByWord.compare(chunks.get(1), chunks.get(2), comparisonPolicy, indicator);
List<TextRange> left = new ArrayList<>();
List<TextRange> base = new ArrayList<>();
List<TextRange> right = new ArrayList<>();
for (DiffFragment wordFragment : fragments1) {
base.add(new TextRange(wordFragment.getStartOffset1(), wordFragment.getEndOffset1()));
left.add(new TextRange(wordFragment.getStartOffset2(), wordFragment.getEndOffset2()));
}
for (DiffFragment wordFragment : fragments2) {
base.add(new TextRange(wordFragment.getStartOffset1(), wordFragment.getEndOffset1()));
right.add(new TextRange(wordFragment.getStartOffset2(), wordFragment.getEndOffset2()));
}
return new MergeInnerDifferences(left, base, right);
}
// ==-, =-=, -==
final ThreeSide side1 = chunks.get(0) != null ? ThreeSide.LEFT : ThreeSide.BASE;
final ThreeSide side2 = chunks.get(2) != null ? ThreeSide.RIGHT : ThreeSide.BASE;
CharSequence chunk1 = side1.select(chunks);
CharSequence chunk2 = side2.select(chunks);
List<DiffFragment> wordConflicts = ByWord.compare(chunk1, chunk2, comparisonPolicy, indicator);
List<List<TextRange>> textRanges = ThreeSide.map(side -> {
if (side == side1) {
return ContainerUtil.map(wordConflicts, fragment -> new TextRange(fragment.getStartOffset1(), fragment.getEndOffset1()));
}
if (side == side2) {
return ContainerUtil.map(wordConflicts, fragment -> new TextRange(fragment.getStartOffset2(), fragment.getEndOffset2()));
}
return null;
});
return new MergeInnerDifferences(textRanges.get(0), textRanges.get(1), textRanges.get(2));
}
Aggregations