Skip to content

Commit 9bf2d84

Browse files
authored
[SuperEditor] - DragHandleAutoScroller: Clamp the scroll offset in ensureOffsetIsVisible (#2128)
1 parent 748b631 commit 9bf2d84

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

super_editor/lib/src/infrastructure/platforms/mobile_documents.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ class DragHandleAutoScroller {
409409
final scrollPosition = _getScrollPosition();
410410
final currentScrollOffset = scrollPosition.pixels;
411411

412+
// The offset calculation below does not work correctly in custom scroll view with sliver header
413+
// and causes overscroll so for now clamp the offset.
414+
final max = scrollPosition.maxScrollExtent;
415+
final min = scrollPosition.minScrollExtent;
416+
412417
if (offsetInViewport.dy < _dragAutoScrollBoundary.leading) {
413418
// The offset is above the leading boundary. We need to scroll up
414419
editorGesturesLog.fine("The scrollable needs to scroll up to make offset visible.");
@@ -417,8 +422,8 @@ class DragHandleAutoScroller {
417422
// at the top edge of the scrollable, so we can't scroll further up.
418423
if (currentScrollOffset > 0.0) {
419424
// Jump to the position where the offset sits at the leading boundary.
420-
scrollPosition.jumpTo(
421-
currentScrollOffset + (offsetInViewport.dy - _dragAutoScrollBoundary.leading),
425+
scrollPosition.jumpTo((
426+
currentScrollOffset + (offsetInViewport.dy - _dragAutoScrollBoundary.leading).clamp(min, max)),
422427
);
423428
}
424429
} else if (offsetInViewport.dy > _getViewportBox().size.height - _dragAutoScrollBoundary.trailing) {
@@ -429,7 +434,7 @@ class DragHandleAutoScroller {
429434
// distance below. Scroll to where the offset sits at the trailing boundary.
430435
final jumpDeltaToShowOffset =
431436
offsetInViewport.dy + _dragAutoScrollBoundary.trailing - _getViewportBox().size.height;
432-
scrollPosition.jumpTo(currentScrollOffset + jumpDeltaToShowOffset);
437+
scrollPosition.jumpTo((currentScrollOffset + jumpDeltaToShowOffset).clamp(min, max));
433438
}
434439
}
435440
}

0 commit comments

Comments
 (0)