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;
}
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);
}
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()));
}
}
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);
}
}
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);
}
}
Aggregations