use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.
the class MergeList method processText.
@NotNull
private static List<MergeFragment> processText(@NotNull String leftText, @NotNull String baseText, @NotNull String rightText, @NotNull ContextLogger logger) throws FilesTooBigForDiffException {
DiffFragment[] leftFragments = DiffPolicy.DEFAULT_LINES.buildFragments(DiffString.create(baseText), DiffString.create(leftText));
DiffFragment[] rightFragments = DiffPolicy.DEFAULT_LINES.buildFragments(DiffString.create(baseText), DiffString.create(rightText));
int[] leftOffsets = { 0, 0 };
int[] rightOffsets = { 0, 0 };
int leftIndex = 0;
int rightIndex = 0;
MergeBuilder builder = new MergeBuilder(logger);
while (leftIndex < leftFragments.length || rightIndex < rightFragments.length) {
FragmentSide side;
TextRange[] equalRanges = new TextRange[2];
if (leftOffsets[0] < rightOffsets[0] && leftIndex < leftFragments.length) {
side = FragmentSide.SIDE1;
getEqualRanges(leftFragments[leftIndex], leftOffsets, equalRanges);
leftIndex++;
} else if (rightIndex < rightFragments.length) {
side = FragmentSide.SIDE2;
getEqualRanges(rightFragments[rightIndex], rightOffsets, equalRanges);
rightIndex++;
} else
break;
if (equalRanges[0] != null && equalRanges[1] != null)
builder.add(equalRanges[0], equalRanges[1], side);
else
logger.assertTrue(equalRanges[0] == null && equalRanges[1] == null);
}
return builder.finish(leftText.length(), baseText.length(), rightText.length());
}
use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.
the class PreferWholeLines method correct.
public DiffFragment[] correct(DiffFragment[] fragments) {
for (int i = 1; i < fragments.length - 1; i++) {
DiffFragment fragment = fragments[i];
if (!fragment.isOneSide())
continue;
DiffFragment nextFragment = fragments[i + 1];
FragmentSide side = FragmentSide.chooseSide(fragment);
DiffString fragmentText = side.getText(fragment);
DiffString otherNextFragmentText = side.getOtherText(nextFragment);
DiffString nextFragmentText = side.getText(nextFragment);
if (nextFragment.isOneSide()) {
LOG.error("<" + fragmentText + "> <" + otherNextFragmentText + ">");
}
if (StringUtil.startsWithChar(fragmentText, '\n') && StringUtil.startsWithChar(nextFragmentText, '\n') && StringUtil.startsWithChar(otherNextFragmentText, '\n')) {
DiffFragment previous = fragments[i - 1];
DiffString previousText = side.getText(previous);
DiffString otherPreciousText = side.getOtherText(previous);
assert previous != null;
assert previousText != null;
assert otherPreciousText != null;
assert fragmentText != null;
assert nextFragmentText != null;
assert otherNextFragmentText != null;
previous = side.createFragment(previousText.append('\n'), otherPreciousText.append('\n'), previous.isModified());
fragments[i - 1] = previous;
fragment = side.createFragment(fragmentText.substring(1).append('\n'), side.getOtherText(fragment), fragment.isModified());
fragments[i] = fragment;
nextFragment = side.createFragment(nextFragmentText.substring(1), otherNextFragmentText.substring(1), nextFragment.isModified());
fragments[i + 1] = nextFragment;
}
}
return fragments;
}
use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.
the class UniteSameType method covertSequentialOneSideToChange.
@NotNull
private static DiffFragment[] covertSequentialOneSideToChange(@NotNull DiffFragment[] fragments) {
if (fragments.length < 2)
return fragments;
DiffCorrection.FragmentsCollector collector = new DiffCorrection.FragmentsCollector();
// DiffFragment previous = fragments[0];
DiffFragment previous = null;
for (int i = 0; i < fragments.length; i++) {
DiffFragment fragment = fragments[i];
if (fragment.isOneSide()) {
if (previous == null)
previous = fragment;
else {
FragmentSide side = FragmentSide.chooseSide(fragment);
DiffString previousText = side.getText(previous);
if (previousText == null)
previousText = DiffString.EMPTY;
previous = side.createFragment(DiffString.concatenateNullable(previousText, side.getText(fragment)), side.getOtherText(previous), true);
}
} else {
if (previous != null)
collector.add(previous);
previous = null;
collector.add(fragment);
}
}
if (previous != null)
collector.add(previous);
return collector.toArray();
}
use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.
the class SyncScrollSupport method syncHorizontalScroll.
private static void syncHorizontalScroll(@NotNull ScrollingContext context, @NotNull Rectangle newRectangle, @NotNull Rectangle oldRectangle) {
int newScrollOffset = newRectangle.x;
if (newScrollOffset == oldRectangle.x)
return;
EditingSides sidesContainer = context.getSidesContainer();
FragmentSide masterSide = context.getMasterSide();
Editor slaveEditor = sidesContainer.getEditor(masterSide.otherSide());
if (slaveEditor == null)
return;
doScrollHorizontally(slaveEditor.getScrollingModel(), newScrollOffset);
}
use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.
the class SyncScrollSupport method syncVerticalScroll.
private static void syncVerticalScroll(@NotNull ScrollingContext context, @NotNull Rectangle newRectangle, @NotNull Rectangle oldRectangle) {
if (newRectangle.y == oldRectangle.y)
return;
EditingSides sidesContainer = context.getSidesContainer();
FragmentSide masterSide = context.getMasterSide();
FragmentSide masterDiffSide = context.getMasterDiffSide();
Editor master = sidesContainer.getEditor(masterSide);
Editor slave = sidesContainer.getEditor(masterSide.otherSide());
if (master == null || slave == null)
return;
if (master.isDisposed() || slave.isDisposed())
return;
int masterVerticalScrollOffset = master.getScrollingModel().getVerticalScrollOffset();
int slaveVerticalScrollOffset = slave.getScrollingModel().getVerticalScrollOffset();
Rectangle viewRect = master.getScrollingModel().getVisibleArea();
int middleY = viewRect.height / 3;
if (master.getDocument().getTextLength() == 0)
return;
LogicalPosition masterPos = master.xyToLogicalPosition(new Point(viewRect.x, masterVerticalScrollOffset + middleY));
int masterCenterLine = masterPos.line;
int scrollToLine = sidesContainer.getLineBlocks().transform(masterDiffSide, masterCenterLine);
int offset;
if (scrollToLine < 0) {
offset = slaveVerticalScrollOffset + newRectangle.y - oldRectangle.y;
} else {
int correction = (masterVerticalScrollOffset + middleY) % master.getLineHeight();
Point point = slave.logicalPositionToXY(new LogicalPosition(scrollToLine, masterPos.column));
offset = point.y - middleY + correction;
}
int deltaHeaderOffset = getHeaderOffset(slave) - getHeaderOffset(master);
doScrollVertically(slave.getScrollingModel(), offset + deltaHeaderOffset);
}
Aggregations