void (boolean stopAnimation) { int newY; if (myTopLeftCornerMarker == null) { newY = myEditor.visualLineToY(myEditor.getCaretModel().getVisualPosition().line); } else { if (!myTopLeftCornerMarker.isValid()) return; newY = myEditor.offsetToXY(myTopLeftCornerMarker.getStartOffset()).y; } ScrollingModel scrollingModel = myEditor.getScrollingModel(); Rectangle targetArea = scrollingModel.getVisibleAreaOnScrollingFinished(); // when animated scrolling is in progress, we'll not stop it immediately boolean disableAnimation = targetArea.equals(scrollingModel.getVisibleArea()) || stopAnimation; if (disableAnimation) scrollingModel.disableAnimation(); scrollingModel.scroll(targetArea.x, newY - myViewportShift); // can't use 'scrollVertically' - it aborts horizontal scrolling if (disableAnimation) scrollingModel.enableAnimation(); }