chore: add jumpTo to editor scroll service (#466)
This commit is contained in:
parent
a97c816c1d
commit
f5b3ea87f5
4 changed files with 26 additions and 14 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
edgeOffset: 100,
|
||||
duration: Duration.zero,
|
||||
);
|
||||
} else {
|
||||
startAutoScroll(endTouchPoint, duration: Duration.zero);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,6 +302,9 @@ class ScrollOffsetController {
|
|||
);
|
||||
}
|
||||
|
||||
void jumpTo({required double offset}) =>
|
||||
_scrollableListState!.primary.scrollController.jumpTo(offset);
|
||||
|
||||
_ScrollablePositionedListState? _scrollableListState;
|
||||
|
||||
void _attach(_ScrollablePositionedListState scrollableListState) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue