From 84eacf02c1b4269b5c76c21177de9785dd5aba69 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Tue, 18 Apr 2017 11:13:28 +0300 Subject: [PATCH] IDEA-170583 "Reformat Code" leads to weird scrolling in the editor window ensuring all possible cases are covered --- .../codeInsight/actions/ReformatCodeProcessor.java | 4 ++-- .../codeInsight/hints/ParameterHintsPassFactory.java | 2 +- .../editor/ex/util/CaretVisualPositionKeeper.java | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java index 4bf4864316a1..f88c2b3b7155 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/ReformatCodeProcessor.java @@ -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); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPassFactory.java index 9ec8d8027e1c..8073d67c8b45 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/ParameterHintsPassFactory.java @@ -139,7 +139,7 @@ public class ParameterHintsPassFactory extends AbstractProjectComponent implemen List hints = getParameterHints(manager); ParameterHintsUpdater updater = new ParameterHintsUpdater(myEditor, hints, myHints, myShowOnlyIfExistedBeforeHints); updater.update(); - keeper.restoreOriginalLocation(); + keeper.restoreOriginalLocation(false); } @NotNull diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/CaretVisualPositionKeeper.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/CaretVisualPositionKeeper.java index 2bde57616bf2..0676650ba8fc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/CaretVisualPositionKeeper.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/util/CaretVisualPositionKeeper.java @@ -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 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(); } } }