Search in sources :

Example 1 with LineRange

use of com.intellij.diff.util.LineRange in project intellij-community by JetBrains.

the class FoldingModelSupport method getFoldedRanges.

@NotNull
private List<FoldedRangeState> getFoldedRanges(int index, @NotNull Settings settings) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    List<FoldedRangeState> ranges = new ArrayList<>();
    DocumentEx document = myEditors[index].getDocument();
    for (FoldedBlock[] blocks : myFoldings) {
        LineRange expanded = null;
        LineRange collapsed = null;
        for (FoldedBlock folding : blocks) {
            FoldRegion region = folding.getRegion(index);
            if (region == null || !region.isValid())
                continue;
            if (region.isExpanded()) {
                if (expanded == null) {
                    int line1 = document.getLineNumber(region.getStartOffset());
                    int line2 = document.getLineNumber(region.getEndOffset()) + 1;
                    expanded = new LineRange(line1, line2);
                }
            } else {
                int line1 = document.getLineNumber(region.getStartOffset());
                int line2 = document.getLineNumber(region.getEndOffset()) + 1;
                collapsed = new LineRange(line1, line2);
                break;
            }
        }
        if (expanded != null || collapsed != null) {
            ranges.add(new FoldedRangeState(expanded, collapsed));
        }
    }
    return ranges;
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) ArrayList(java.util.ArrayList) FoldRegion(com.intellij.openapi.editor.FoldRegion) LineRange(com.intellij.diff.util.LineRange) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with LineRange

use of com.intellij.diff.util.LineRange in project intellij-community by JetBrains.

the class AppliedTextPatch method create.

public static AppliedTextPatch create(@NotNull List<AppliedSplitPatchHunk> splitPatchHunkList) {
    List<AppliedSplitPatchHunk> hunks = new ArrayList<>(splitPatchHunkList);
    // ensure, that `appliedTo` ranges do not overlap
    BitSet appliedLines = new BitSet();
    for (int i = 0; i < hunks.size(); i++) {
        AppliedSplitPatchHunk hunk = hunks.get(i);
        LineRange appliedTo = hunk.getAppliedTo();
        if (appliedTo == null)
            continue;
        int nextAppliedLine = appliedLines.nextSetBit(appliedTo.start);
        if (nextAppliedLine != -1 && nextAppliedLine < appliedTo.end) {
            hunks.set(i, new AppliedSplitPatchHunk(hunk, -1, -1, NOT_APPLIED));
        } else {
            appliedLines.set(appliedTo.start, appliedTo.end, true);
        }
    }
    ContainerUtil.sort(hunks, Comparator.comparingInt(o -> o.getLineRangeBefore().start));
    return new AppliedTextPatch(hunks);
}
Also used : GenericPatchApplier(com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier) List(java.util.List) BeforeAfter(com.intellij.util.BeforeAfter) BitSet(java.util.BitSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) LineRange(com.intellij.diff.util.LineRange) NOT_APPLIED(com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.HunkStatus.NOT_APPLIED) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) LineRange(com.intellij.diff.util.LineRange)

Example 3 with LineRange

use of com.intellij.diff.util.LineRange in project intellij-community by JetBrains.

the class PatchChangeBuilder method exec.

public void exec(@NotNull List<AppliedSplitPatchHunk> splitHunks) {
    int lastBeforeLine = -1;
    for (AppliedSplitPatchHunk hunk : splitHunks) {
        List<String> contextBefore = hunk.getContextBefore();
        List<String> contextAfter = hunk.getContextAfter();
        LineRange beforeRange = hunk.getLineRangeBefore();
        LineRange afterRange = hunk.getLineRangeAfter();
        int overlappedContext = 0;
        if (lastBeforeLine != -1) {
            if (lastBeforeLine >= beforeRange.start) {
                overlappedContext = lastBeforeLine - beforeRange.start + 1;
            } else if (lastBeforeLine < beforeRange.start - 1) {
                appendSeparator();
            }
        }
        List<String> trimContext = contextBefore.subList(overlappedContext, contextBefore.size());
        addContext(trimContext, beforeRange.start + overlappedContext, afterRange.start + overlappedContext);
        int deletion = totalLines;
        appendLines(hunk.getDeletedLines());
        int insertion = totalLines;
        appendLines(hunk.getInsertedLines());
        int hunkEnd = totalLines;
        myConvertor1.put(deletion, beforeRange.start + contextBefore.size(), insertion - deletion);
        myConvertor2.put(insertion, afterRange.start + contextBefore.size(), hunkEnd - insertion);
        addContext(contextAfter, beforeRange.end - contextAfter.size(), afterRange.end - contextAfter.size());
        lastBeforeLine = beforeRange.end - 1;
        LineRange deletionRange = new LineRange(deletion, insertion);
        LineRange insertionRange = new LineRange(insertion, hunkEnd);
        myHunks.add(new Hunk(hunk.getInsertedLines(), deletionRange, insertionRange, hunk.getAppliedTo(), hunk.getStatus()));
    }
}
Also used : AppliedSplitPatchHunk(com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.AppliedSplitPatchHunk) AppliedSplitPatchHunk(com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.AppliedSplitPatchHunk) LineRange(com.intellij.diff.util.LineRange)

Example 4 with LineRange

use of com.intellij.diff.util.LineRange in project intellij-community by JetBrains.

the class DiffRequestProcessor method notifyMessage.

private void notifyMessage(@NotNull AnActionEvent e, boolean next) {
    Editor editor = e.getData(DiffDataKeys.CURRENT_EDITOR);
    // TODO: provide "change" word in chain UserData - for tests/etc
    String message = DiffUtil.createNotificationText(next ? "Press again to go to the next file" : "Press again to go to the previous file", "You can disable this feature in " + DiffUtil.getSettingsConfigurablePath());
    final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
    Point point = new Point(myContentPanel.getWidth() / 2, next ? myContentPanel.getHeight() - JBUI.scale(40) : JBUI.scale(40));
    if (editor == null) {
        final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        final HintHint hintHint = createNotifyHint(myContentPanel, point, next);
        hint.show(myContentPanel, point.x, point.y, owner instanceof JComponent ? (JComponent) owner : null, hintHint);
    } else {
        int x = SwingUtilities.convertPoint(myContentPanel, point, editor.getComponent()).x;
        JComponent header = editor.getHeaderComponent();
        int shift = editor.getScrollingModel().getVerticalScrollOffset() - (header != null ? header.getHeight() : 0);
        LogicalPosition position;
        LineRange changeRange = e.getData(DiffDataKeys.CURRENT_CHANGE_RANGE);
        if (changeRange == null) {
            position = new LogicalPosition(editor.getCaretModel().getLogicalPosition().line + (next ? 1 : 0), 0);
        } else {
            position = new LogicalPosition(next ? changeRange.end : changeRange.start, 0);
        }
        int y = editor.logicalPositionToXY(position).y - shift;
        Point editorPoint = new Point(x, y);
        final HintHint hintHint = createNotifyHint(editor.getComponent(), editorPoint, !next);
        HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, editorPoint, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Editor(com.intellij.openapi.editor.Editor) LineRange(com.intellij.diff.util.LineRange) LightweightHint(com.intellij.ui.LightweightHint) HintHint(com.intellij.ui.HintHint)

Example 5 with LineRange

use of com.intellij.diff.util.LineRange in project intellij-community by JetBrains.

the class MergeModelBase method setChanges.

public void setChanges(@NotNull List<LineRange> changes) {
    myStartLines.clear(changes.size());
    myEndLines.clear(changes.size());
    for (LineRange range : changes) {
        myStartLines.add(range.start);
        myEndLines.add(range.end);
    }
}
Also used : LineRange(com.intellij.diff.util.LineRange)

Aggregations

LineRange (com.intellij.diff.util.LineRange)5 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 GenericPatchApplier (com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier)1 Editor (com.intellij.openapi.editor.Editor)1 FoldRegion (com.intellij.openapi.editor.FoldRegion)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)1 AppliedSplitPatchHunk (com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.AppliedSplitPatchHunk)1 NOT_APPLIED (com.intellij.openapi.vcs.changes.patch.AppliedTextPatch.HunkStatus.NOT_APPLIED)1 HintHint (com.intellij.ui.HintHint)1 LightweightHint (com.intellij.ui.LightweightHint)1 BeforeAfter (com.intellij.util.BeforeAfter)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 BitSet (java.util.BitSet)1 Comparator (java.util.Comparator)1 List (java.util.List)1