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 { class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key); const MyApp({super.key});
@override @override
Widget build(BuildContext context) { 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() { void jumpToTop() {
if (shrinkWrap) { if (shrinkWrap) {
scrollController.jumpTo(0); scrollController.jumpTo(0);

View file

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

View file

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