IDEA-170583 "Reformat Code" leads to weird scrolling in the editor window

ensuring all possible cases are covered
This commit is contained in:
Dmitry Batrak
2017-04-18 11:14:46 +03:00
parent fcdf19f49a
commit 84eacf02c1
3 changed files with 8 additions and 8 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -129,7 +129,7 @@ public class ReformatCodeProcessor extends AbstractLayoutCodeProcessor {
CodeStyleManager.getInstance(myProject).reformatText(file, ranges);
}
caretPositionKeeper.restoreOriginalLocation();
caretPositionKeeper.restoreOriginalLocation(true);
if (before != null) {
prepareUserNotificationMessage(document, before);
@@ -139,7 +139,7 @@ public class ParameterHintsPassFactory extends AbstractProjectComponent implemen
List<Inlay> hints = getParameterHints(manager);
ParameterHintsUpdater updater = new ParameterHintsUpdater(myEditor, hints, myHints, myShowOnlyIfExistedBeforeHints);
updater.update();
keeper.restoreOriginalLocation();
keeper.restoreOriginalLocation(false);
}
@NotNull
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,7 +49,7 @@ public class CaretVisualPositionKeeper {
}
}
public void restoreOriginalLocation() {
public void restoreOriginalLocation(boolean stopAnimation) {
for (Map.Entry<Editor, Integer> e : myCaretRelativeVerticalPositions.entrySet()) {
Editor editor = e.getKey();
int relativePosition = e.getValue();
@@ -58,10 +58,10 @@ public class CaretVisualPositionKeeper {
ScrollingModel scrollingModel = editor.getScrollingModel();
Rectangle targetArea = scrollingModel.getVisibleAreaOnScrollingFinished();
// when animated scrolling is in progress, we'll not stop it immediately
boolean useAnimation = !targetArea.equals(scrollingModel.getVisibleArea());
if (!useAnimation) scrollingModel.disableAnimation();
boolean disableAnimation = targetArea.equals(scrollingModel.getVisibleArea()) || stopAnimation;
if (disableAnimation) scrollingModel.disableAnimation();
scrollingModel.scroll(targetArea.x, scrollOffset);
if (!useAnimation) scrollingModel.enableAnimation();
if (disableAnimation) scrollingModel.enableAnimation();
}
}
}