Search in sources :

Example 1 with TextDiffType

use of com.intellij.openapi.diff.impl.util.TextDiffType in project intellij-community by JetBrains.

the class DividerPolygon method createVisiblePolygons.

public static ArrayList<DividerPolygon> createVisiblePolygons(@NotNull EditingSides sides, @NotNull FragmentSide left, int diffDividerPolygonsOffset) {
    Editor editor1 = sides.getEditor(left);
    Editor editor2 = sides.getEditor(left.otherSide());
    LineBlocks lineBlocks = sides.getLineBlocks();
    Trapezium visibleArea = new Trapezium(getVisibleInterval(editor1), getVisibleInterval(editor2));
    Interval indices = lineBlocks.getVisibleIndices(visibleArea);
    Transformation[] transformations = new Transformation[] { getTransformation(editor1), getTransformation(editor2) };
    ArrayList<DividerPolygon> polygons = new ArrayList<>();
    for (int i = indices.getStart(); i < indices.getEnd(); i++) {
        Trapezium trapezium = lineBlocks.getTrapezium(i);
        final TextDiffType type = lineBlocks.getType(i);
        Color color = type.getPolygonColor(editor1);
        polygons.add(createPolygon(transformations, trapezium, color, left, diffDividerPolygonsOffset, type.isApplied()));
    }
    return polygons;
}
Also used : ArrayList(java.util.ArrayList) TextDiffType(com.intellij.openapi.diff.impl.util.TextDiffType) Editor(com.intellij.openapi.editor.Editor)

Example 2 with TextDiffType

use of com.intellij.openapi.diff.impl.util.TextDiffType in project intellij-community by JetBrains.

the class DiffMarkup method highlightText.

public void highlightText(@NotNull Fragment fragment, @Nullable GutterIconRenderer gutterIconRenderer) {
    MarkupModel markupModel = getMarkupModel();
    EditorEx editor = getEditor();
    TextDiffTypeEnum diffTypeEnum = fragment.getType();
    if (diffTypeEnum == null || markupModel == null || editor == null) {
        return;
    }
    TextDiffType type = fragment instanceof LineFragment ? DiffUtil.makeTextDiffType((LineFragment) fragment) : TextDiffType.create(diffTypeEnum);
    final TextRange range = fragment.getRange(getSide());
    final TextAttributes attributes = type.getTextAttributes(editor);
    if (attributes == null) {
        return;
    }
    RangeHighlighter rangeMarker;
    if (range.getLength() == 0) {
        final int offset = range.getStartOffset();
        rangeMarker = markupModel.addRangeHighlighter(offset, offset, LAYER, attributes, HighlighterTargetArea.EXACT_RANGE);
        rangeMarker.setCustomRenderer(new CustomHighlighterRenderer() {

            @Override
            public void paint(@NotNull Editor ed, @NotNull RangeHighlighter highlighter, @NotNull Graphics g) {
                g.setColor(attributes.getBackgroundColor());
                Point point = ed.logicalPositionToXY(ed.offsetToLogicalPosition(highlighter.getStartOffset()));
                int endy = point.y + ed.getLineHeight() - 1;
                g.drawLine(point.x, point.y, point.x, endy);
                g.drawLine(point.x - 1, point.y, point.x - 1, endy);
            }
        });
    } else {
        rangeMarker = markupModel.addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), LAYER, attributes, HighlighterTargetArea.EXACT_RANGE);
    }
    if (gutterIconRenderer != null) {
        rangeMarker.setGutterIconRenderer(gutterIconRenderer);
    }
    setLineMarkerRenderer(rangeMarker, fragment, type);
    rangeMarker.setThinErrorStripeMark(true);
    if (DiffUtil.isInlineWrapper(fragment)) {
        rangeMarker.setErrorStripeMarkColor(null);
    }
    saveHighlighter(rangeMarker);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) TextDiffTypeEnum(com.intellij.openapi.diff.impl.util.TextDiffTypeEnum) TextDiffType(com.intellij.openapi.diff.impl.util.TextDiffType) TextRange(com.intellij.openapi.util.TextRange) LineFragment(com.intellij.openapi.diff.impl.fragments.LineFragment) Editor(com.intellij.openapi.editor.Editor)

Aggregations

TextDiffType (com.intellij.openapi.diff.impl.util.TextDiffType)2 Editor (com.intellij.openapi.editor.Editor)2 LineFragment (com.intellij.openapi.diff.impl.fragments.LineFragment)1 TextDiffTypeEnum (com.intellij.openapi.diff.impl.util.TextDiffTypeEnum)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 TextRange (com.intellij.openapi.util.TextRange)1 ArrayList (java.util.ArrayList)1