Search in sources :

Example 1 with Side

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

the class ChunkOptimizer method processLastRanges.

private void processLastRanges() {
    // nothing to do
    if (myRanges.size() < 2)
        return;
    Range range1 = myRanges.get(myRanges.size() - 2);
    Range range2 = myRanges.get(myRanges.size() - 1);
    if (range1.end1 != range2.start1 && range1.end2 != range2.start2) {
        // it means that given DiffIterable is not LCS (because we can build a smaller one). This should not happen.
        return;
    }
    int count1 = range1.end1 - range1.start1;
    int count2 = range2.end1 - range2.start1;
    int equalForward = expandForward(myData1, myData2, range1.end1, range1.end2, range1.end1 + count2, range1.end2 + count2);
    int equalBackward = expandBackward(myData1, myData2, range2.start1 - count1, range2.start2 - count1, range2.start1, range2.start2);
    // nothing to do
    if (equalForward == 0 && equalBackward == 0)
        return;
    // merge chunks left [A]B[B] -> [AB]B
    if (equalForward == count2) {
        myRanges.remove(myRanges.size() - 1);
        myRanges.remove(myRanges.size() - 1);
        myRanges.add(new Range(range1.start1, range1.end1 + count2, range1.start2, range1.end2 + count2));
        processLastRanges();
        return;
    }
    // merge chunks right [A]A[B] -> A[AB]
    if (equalBackward == count1) {
        myRanges.remove(myRanges.size() - 1);
        myRanges.remove(myRanges.size() - 1);
        myRanges.add(new Range(range2.start1 - count1, range2.end1, range2.start2 - count1, range2.end2));
        processLastRanges();
        return;
    }
    Side touchSide = Side.fromLeft(range1.end1 == range2.start1);
    int shift = getShift(touchSide, equalForward, equalBackward, range1, range2);
    if (shift != 0) {
        myRanges.remove(myRanges.size() - 1);
        myRanges.remove(myRanges.size() - 1);
        myRanges.add(new Range(range1.start1, range1.end1 + shift, range1.start2, range1.end2 + shift));
        myRanges.add(new Range(range2.start1 + shift, range2.end1, range2.start2 + shift, range2.end2));
    }
}
Also used : Side(com.intellij.diff.util.Side) Range(com.intellij.diff.util.Range)

Example 2 with Side

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

the class TwosideTextDiffViewer method getNavigatable.

//
// Misc
//
@Nullable
@Override
protected Navigatable getNavigatable() {
    Side side = getCurrentSide();
    LineCol position = LineCol.fromCaret(getEditor(side));
    Navigatable navigatable = getContent(side).getNavigatable(position);
    if (navigatable != null)
        return navigatable;
    LineCol otherPosition = transferPosition(side, position);
    return getContent(side.other()).getNavigatable(otherPosition);
}
Also used : Side(com.intellij.diff.util.Side) LineCol(com.intellij.diff.util.LineCol) Navigatable(com.intellij.pom.Navigatable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Side (com.intellij.diff.util.Side)2 LineCol (com.intellij.diff.util.LineCol)1 Range (com.intellij.diff.util.Range)1 Navigatable (com.intellij.pom.Navigatable)1 Nullable (org.jetbrains.annotations.Nullable)1