int (@NotNull Editor editor, int visualLine, int yIncrement) { int startY = editor.visualLineToY(visualLine) + (yIncrement > 0 ? editor.getLineHeight() - 1 : 0); int targetY = startY + yIncrement; int targetVisualLine = editor.yToVisualLine(targetY); int targetVisualLineBase = editor.visualLineToY(targetVisualLine); if (targetY < targetVisualLineBase) { if (yIncrement < 0) targetVisualLine--; } else if (targetY >= targetVisualLineBase + editor.getLineHeight()) { if (yIncrement > 0) targetVisualLine++; } return targetVisualLine - visualLine; }