From e1494d090ee4ef42bfcf594fc9b0b8a9ee302b85 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 25 May 2015 18:20:26 +0300 Subject: [PATCH] diff: fix scrolling on 'prev/next difference' action * fix typos * scroll slave editor to final destination even if master editor haven't scrolled to the end this could happen if we made a mistake in getTargetOffsets() and master editor wasn't scrolled till the target position (because editor can't be scrolled to the required position) --- .../intellij/diff/tools/util/SyncScrollSupport.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/SyncScrollSupport.java b/platform/diff-impl/src/com/intellij/diff/tools/util/SyncScrollSupport.java index e0447120699d..6930cb2f2f1c 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/SyncScrollSupport.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/SyncScrollSupport.java @@ -124,10 +124,12 @@ public class SyncScrollSupport { myHelper1.removeAnchor(); myHelper2.removeAnchor(); - if (masterOffset == masterStartOffset) { // master editor didn't scrolled + int masterFinalOffset = masterEditor.getScrollingModel().getVisibleArea().y; + int slaveFinalOffset = slaveEditor.getScrollingModel().getVisibleArea().y; + if (slaveFinalOffset != slaveOffset) { myDuringSyncScroll = true; - doScrollVertically(slaveEditor, slaveOffset, animate); + doScrollVertically(slaveEditor, slaveOffset, animate && masterFinalOffset == masterStartOffset); slaveEditor.getScrollingModel().runActionOnScrollingFinished(new Runnable() { @Override @@ -318,7 +320,7 @@ public class SyncScrollSupport { int editorHeight2 = editor2.getScrollingModel().getVisibleArea().height; int maximumOffset1 = ((EditorEx)editor1).getScrollPane().getVerticalScrollBar().getMaximum() - editorHeight1; - int maximumOffset2 = ((EditorEx)editor1).getScrollPane().getVerticalScrollBar().getMaximum() - editorHeight2; + int maximumOffset2 = ((EditorEx)editor2).getScrollPane().getVerticalScrollBar().getMaximum() - editorHeight2; // 'shift' here - distance between editor's top and first line of range @@ -340,7 +342,7 @@ public class SyncScrollSupport { if (maximumOffset1 > offset1 && maximumOffset2 > offset2) return new IntPair(offset1, offset2); // One of the ranges is at end of file - we can't scroll where we want to. - topShift = Math.min(topOffset1 - maximumOffset1, topOffset2 - maximumOffset2); + topShift = Math.max(topOffset1 - maximumOffset1, topOffset2 - maximumOffset2); // Try to show as much of range as we can (even if it breaks alignment) offset1 = topOffset1 - topShift + Math.max(topShift + rangeHeight1 + gapLines1 - editorHeight1, 0);