chore: add jumpTo to editor scroll service (#466)

This commit is contained in:
Mathias Mogensen 2023-09-15 00:02:05 +02:00 • committed by GitHub
commit f5b3ea87f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 14 deletions

View file

@ -8,7 +8,7 @@ void main() {
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});
@override
Widget build(BuildContext context) {

View file

@ -169,6 +169,21 @@ class EditorScrollController {
}
}
void jumpTo({
required double offset,
}) async {
if (shrinkWrap) {
return scrollController.jumpTo(
offset.clamp(
scrollController.position.minScrollExtent,
scrollController.position.maxScrollExtent,
),
);
}
scrollOffsetController.jumpTo(offset: max(0, offset));
}
void jumpToTop() {
if (shrinkWrap) {
scrollController.jumpTo(0);

View file

@ -105,32 +105,26 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
if (editorState.selectionUpdateReason ==
SelectionUpdateReason.searchNavigate) {
widget.editorScrollController.animateTo(
offset: endTouchPoint.dy - 100,
duration: const Duration(microseconds: 1),
);
return;
return widget.editorScrollController
.jumpTo(offset: endTouchPoint.dy - 100);
}
if (selection.isCollapsed) {
if (PlatformExtension.isMobile) {
// soft keyboard
// workaround: wait for the soft keyboard to show up
Future.delayed(const Duration(milliseconds: 300), () {
return Future.delayed(const Duration(milliseconds: 300), () {
startAutoScroll(endTouchPoint, edgeOffset: 50);
});
} else {
}
startAutoScroll(
endTouchPoint,
edgeOffset: 100,
duration: Duration.zero,
);
}
} else {
startAutoScroll(
endTouchPoint,
duration: Duration.zero,
);
startAutoScroll(endTouchPoint, duration: Duration.zero);
}
});
}

View file

@ -302,6 +302,9 @@ class ScrollOffsetController {
);
}
void jumpTo({required double offset}) =>
_scrollableListState!.primary.scrollController.jumpTo(offset);
_ScrollablePositionedListState? _scrollableListState;
void _attach(_ScrollablePositionedListState scrollableListState) {