movePageUp function
NavigationResult
movePageUp(
- Root root,
- CaretStop current,
- double preferredX,
- CaretXResolver resolveX,
- CaretYResolver resolveY, {
- List<
LogicalLine> ? lines,
Moves the cursor up by approximately 10-15 logical lines.
Implementation
NavigationResult movePageUp(
Root root,
CaretStop current,
double preferredX,
CaretXResolver resolveX,
CaretYResolver resolveY, {
List<LogicalLine>? lines,
}) {
final lines_ = lines ?? buildAllLogicalLines(root);
final lineInfo = findLineForStop(lines_, current);
if (lineInfo == null) return NavigationResult.none;
final currentLineIndex = lineInfo.lineIndex;
final targetLineIndex = (currentLineIndex - 10).clamp(0, lines_.length - 1);
if (targetLineIndex == currentLineIndex) {
// Already at or near the top, go to document start
final stops = buildAllStops(root);
if (stops.isEmpty) return NavigationResult.none;
final firstStop = stops.first;
if (firstStop == current) return NavigationResult.none;
return NavigationResult(position: firstStop, preferredX: preferredX);
}
final targetLine = lines_[targetLineIndex];
if (targetLine.stops.isEmpty) return NavigationResult.none;
final x = preferredX >= 0.0 ? preferredX : resolveX(current);
final best = _stopNearestX(targetLine.stops, x, resolveX);
return NavigationResult(position: best, preferredX: x);
}