diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/ChunkOptimizer.java b/platform/diff-impl/src/com/intellij/diff/comparison/ChunkOptimizer.java index b1e97aadbbd5..993b735e39d7 100644 --- a/platform/diff-impl/src/com/intellij/diff/comparison/ChunkOptimizer.java +++ b/platform/diff-impl/src/com/intellij/diff/comparison/ChunkOptimizer.java @@ -82,6 +82,9 @@ abstract class ChunkOptimizer { 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); @@ -226,12 +229,12 @@ abstract class ChunkOptimizer { List touchLines = touchSide.select(myData1, myData2); int touchStart = touchSide.select(range2.start1, range2.start2); - int shiftForward = findNextUnimportantLine(touchLines, touchStart, equalForward, 0); - int shiftBackward = findPrevUnimportantLine(touchLines, touchStart - 1, equalBackward, 0); + int shiftForward = findNextUnimportantLine(touchLines, touchStart, equalForward + 1, 0); + int shiftBackward = findPrevUnimportantLine(touchLines, touchStart - 1, equalBackward + 1, 0); if (shiftForward == -1 && shiftBackward == -1 && myThreshold != 0) { - shiftForward = findNextUnimportantLine(touchLines, touchStart, equalForward, myThreshold); - shiftBackward = findPrevUnimportantLine(touchLines, touchStart - 1, equalBackward, myThreshold); + shiftForward = findNextUnimportantLine(touchLines, touchStart, equalForward + 1, myThreshold); + shiftBackward = findPrevUnimportantLine(touchLines, touchStart - 1, equalBackward + 1, myThreshold); } if (shiftForward == 0 || shiftBackward == 0) return 0; diff --git a/platform/diff-impl/tests/com/intellij/diff/comparison/LineComparisonUtilTest.kt b/platform/diff-impl/tests/com/intellij/diff/comparison/LineComparisonUtilTest.kt index e97750d310a5..fe4e76b9d7c0 100644 --- a/platform/diff-impl/tests/com/intellij/diff/comparison/LineComparisonUtilTest.kt +++ b/platform/diff-impl/tests/com/intellij/diff/comparison/LineComparisonUtilTest.kt @@ -269,6 +269,12 @@ class LineComparisonUtilTest : ComparisonUtilTestBase() { testAll() } + lines { + ("A_B_o_o_Y_Z_ _A_B_ _ _Y_Z" - "A_B_o_o_Y_Z_ _A_B_u_u_Y_Z_ _A_B_ _ _Y_Z") + default(ins(9, 9, 7)) + testAll() + } + lines { ("A_B_o_o_ _A_B_z_z" - "A_B_o_o_ _A_B_u_u_ _A_B_z_z") default(ins(5, 5, 5))