ProperTextRange (int start, int end) { if (!dimensionsAreValid) { recalcEditorDimensions(); } Document document = myEditor.getDocument(); int startLineNumber = end == -1 ? 0 : offsetToLine(start, document); int editorStartY = myEditor.visualLineToY(startLineNumber); int startY; int editorTargetHeight = Math.max(0, myEditorTargetHeight); if (myEditorSourceHeight < editorTargetHeight) { startY = myEditorScrollbarTop + editorStartY; } else { startY = myEditorScrollbarTop + (int)((float)editorStartY / myEditorSourceHeight * editorTargetHeight); } int endY; int endLineNumber = offsetToLine(end, document); if (end == -1 || start == -1) { endY = Math.min(myEditorSourceHeight, editorTargetHeight); } else if (startLineNumber == endLineNumber) { endY = startY; // both offsets are on the same line, no need to re-calc Y position } else if (myEditorSourceHeight < editorTargetHeight) { endY = myEditorScrollbarTop + myEditor.visualLineToY(endLineNumber); } else { int editorEndY = myEditor.visualLineToY(endLineNumber); endY = myEditorScrollbarTop + (int)((float)editorEndY / myEditorSourceHeight * editorTargetHeight); } if (endY < startY) endY = startY; return new ProperTextRange(startY, endY); }