boolean () { Editor editor = mySupplier.getEditor(); // There is a possible case that the editor is configured to show virtual space at file bottom // and the requested position is located somewhere around. // We don't want to position the viewport in a way that most of its area is used to represent that virtual empty space. // So, we tweak vertical offset if necessary. int maxY = Math.max(editor.getLineHeight(), editor.getDocument().getLineCount() * editor.getLineHeight()); int minPreferredY = maxY - getVisibleArea().height * 2 / 3; final int currentOffset = getVerticalScrollOffset(); int offsetToUse = Math.min(minPreferredY, currentOffset); if (offsetToUse != currentOffset) { scroll(getHorizontalScrollOffset(), offsetToUse); return true; } return false; }