IDEA-230636 Editor scrolls on fold/unfold of a code block

GitOrigin-RevId: 13898393797433723d75b741a24c81a8e76c5db7
This commit is contained in:
Dmitry Batrak
2020-02-04 09:10:13 +00:00
committed by intellij-monorepo-bot
parent e51e92738d
commit 70d36bf478
2 changed files with 5 additions and 7 deletions
@@ -1267,10 +1267,6 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
return myEditor.visualLineToY(line) + myEditor.getAscent() - width;
}
int getHeadCenterY(FoldRegion foldRange) {
return getLineCenterY(myEditor.offsetToVisualLine(foldRange.getStartOffset()));
}
private void drawFoldingAnchor(double width, @NotNull Rectangle clip, @NotNull Graphics2D g, int visualLine,
@NotNull DisplayedFoldingAnchor.Type type, boolean active) {
double off = width / 4;
@@ -3901,7 +3901,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
if (range != null) {
final boolean expansion = !range.isExpanded();
int scrollShift = y - getScrollingModel().getVerticalScrollOffset();
int scrollShift = expansion ? 0 : visualLineToY(yToVisualLine(y)) - getScrollingModel().getVerticalScrollOffset();
getFoldingModel().runBatchFoldingOperation(() -> {
range.setExpanded(expansion);
if (e.isAltDown()) {
@@ -3912,8 +3912,10 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
}
}
}, true, false);
y = myGutterComponent.getHeadCenterY(range);
getScrollingModel().scrollVertically(y - scrollShift);
if (!expansion) {
int newY = visualLineToY(offsetToVisualLine(range.getStartOffset()));
EditorUtil.runWithAnimationDisabled(EditorImpl.this, () -> myScrollingModel.scrollVertically(newY - scrollShift));
}
myGutterComponent.updateSize();
validateMousePointer(e);
e.consume();