Search in sources :

Example 1 with Range

use of com.intellij.openapi.vcs.ex.Range in project intellij-community by JetBrains.

the class ShowChangeMarkerAction method actionPerformed.

@Override
protected void actionPerformed(@NotNull VcsContext context) {
    Editor editor = myChangeMarkerContext.getEditor(context);
    LineStatusTracker lineStatusTracker = myChangeMarkerContext.getLineStatusTracker(context);
    Range range = myChangeMarkerContext.getRange(context);
    LineStatusTrackerDrawing.moveToRange(range, editor, lineStatusTracker);
}
Also used : LineStatusTracker(com.intellij.openapi.vcs.ex.LineStatusTracker) Editor(com.intellij.openapi.editor.Editor) Range(com.intellij.openapi.vcs.ex.Range)

Example 2 with Range

use of com.intellij.openapi.vcs.ex.Range in project intellij-community by JetBrains.

the class VcsAwareFormatChangedTextUtil method calculateChangedLinesNumber.

@Override
public int calculateChangedLinesNumber(@NotNull Document document, @NotNull CharSequence contentFromVcs) {
    try {
        List<Range> changedRanges = getRanges(document, contentFromVcs);
        int linesChanges = 0;
        for (Range range : changedRanges) {
            linesChanges += countLines(range);
        }
        return linesChanges;
    } catch (FilesTooBigForDiffException e) {
        LOG.info("File too big, can not calculate changed lines number");
        return -1;
    }
}
Also used : FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Range(com.intellij.openapi.vcs.ex.Range) TextRange(com.intellij.openapi.util.TextRange)

Example 3 with Range

use of com.intellij.openapi.vcs.ex.Range in project intellij-community by JetBrains.

the class VcsAwareFormatChangedTextUtil method getChangedTextRanges.

@NotNull
private static ChangedRangesInfo getChangedTextRanges(@NotNull Document document, @NotNull List<Range> changedRanges) {
    final List<TextRange> ranges = ContainerUtil.newArrayList();
    final List<TextRange> insertedRanges = ContainerUtil.newArrayList();
    for (Range range : changedRanges) {
        if (range.getType() != Range.DELETED) {
            int changeStartLine = range.getLine1();
            int changeEndLine = range.getLine2();
            int lineStartOffset = document.getLineStartOffset(changeStartLine);
            int lineEndOffset = document.getLineEndOffset(changeEndLine - 1);
            TextRange changedTextRange = new TextRange(lineStartOffset, lineEndOffset);
            ranges.add(changedTextRange);
            if (range.getType() == Range.INSERTED) {
                insertedRanges.add(changedTextRange);
            }
        }
    }
    return new ChangedRangesInfo(ranges, insertedRanges);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) ChangedRangesInfo(com.intellij.psi.codeStyle.ChangedRangesInfo) Range(com.intellij.openapi.vcs.ex.Range) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Range

use of com.intellij.openapi.vcs.ex.Range in project intellij-community by JetBrains.

the class VcsPreviewPanel method updateView.

@Override
public void updateView() {
    EditorColorsScheme colorsScheme = myEditor.getColorsScheme();
    StringBuilder sb = new StringBuilder();
    sb.append("Deleted line below\n\n" + "Modified line\n\n" + "Added line\n\n" + "Line with modified whitespaces\n\n" + "Added line\n" + "Line with modified whitespaces and deletion after\n");
    int additionalLines = Math.max(0, AnnotationsSettings.getInstance().getOrderedColors(colorsScheme).size() - StringUtil.countNewLines(sb));
    sb.append(StringUtil.repeat("\n", additionalLines));
    myEditor.getDocument().setText(sb);
    myEditor.getMarkupModel().removeAllHighlighters();
    myEditor.getGutterComponentEx().closeAllAnnotations();
    addHighlighter(new Range(1, 1, 0, 1), EditorColors.DELETED_LINES_COLOR);
    addHighlighter(createModifiedRange(2, Range.MODIFIED), EditorColors.MODIFIED_LINES_COLOR);
    addHighlighter(createModifiedRange(4, Range.INSERTED), EditorColors.ADDED_LINES_COLOR);
    addHighlighter(createModifiedRange(6, Range.EQUAL), EditorColors.WHITESPACES_MODIFIED_LINES_COLOR);
    addHighlighter(createModifiedRange(8, Range.INSERTED, Range.EQUAL, Range.DELETED), EditorColors.WHITESPACES_MODIFIED_LINES_COLOR);
    List<Color> annotationColors = AnnotationsSettings.getInstance().getOrderedColors(colorsScheme);
    List<Integer> anchorIndexes = AnnotationsSettings.getInstance().getAnchorIndexes(colorsScheme);
    myEditor.getGutterComponentEx().registerTextAnnotation(new MyTextAnnotationGutterProvider(annotationColors, anchorIndexes));
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Range(com.intellij.openapi.vcs.ex.Range) TextRange(com.intellij.openapi.util.TextRange) InnerRange(com.intellij.openapi.vcs.ex.Range.InnerRange)

Example 5 with Range

use of com.intellij.openapi.vcs.ex.Range in project intellij-community by JetBrains.

the class VcsPreviewPanel method createModifiedRange.

@NotNull
private static Range createModifiedRange(int currentLine, byte... inner) {
    List<InnerRange> innerRanges = new ArrayList<>();
    int currentInnerLine = currentLine;
    for (byte type : inner) {
        switch(type) {
            case Range.EQUAL:
            case Range.INSERTED:
            case Range.MODIFIED:
                innerRanges.add(new InnerRange(currentInnerLine, currentInnerLine + 1, type));
                currentInnerLine++;
                break;
            case Range.DELETED:
                innerRanges.add(new InnerRange(currentInnerLine, currentInnerLine, type));
                break;
        }
    }
    return new Range(currentLine, currentInnerLine, 0, 1, innerRanges);
}
Also used : ArrayList(java.util.ArrayList) Range(com.intellij.openapi.vcs.ex.Range) TextRange(com.intellij.openapi.util.TextRange) InnerRange(com.intellij.openapi.vcs.ex.Range.InnerRange) InnerRange(com.intellij.openapi.vcs.ex.Range.InnerRange) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Range (com.intellij.openapi.vcs.ex.Range)6 TextRange (com.intellij.openapi.util.TextRange)4 Editor (com.intellij.openapi.editor.Editor)2 LineStatusTracker (com.intellij.openapi.vcs.ex.LineStatusTracker)2 InnerRange (com.intellij.openapi.vcs.ex.Range.InnerRange)2 NotNull (org.jetbrains.annotations.NotNull)2 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 ChangedRangesInfo (com.intellij.psi.codeStyle.ChangedRangesInfo)1 FilesTooBigForDiffException (com.intellij.util.diff.FilesTooBigForDiffException)1 ArrayList (java.util.ArrayList)1