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 {
|
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) {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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(
|
|
||||||
endTouchPoint,
|
|
||||||
edgeOffset: 100,
|
|
||||||
duration: Duration.zero,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
startAutoScroll(
|
startAutoScroll(
|
||||||
endTouchPoint,
|
endTouchPoint,
|
||||||
|
edgeOffset: 100,
|
||||||
duration: Duration.zero,
|
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;
|
_ScrollablePositionedListState? _scrollableListState;
|
||||||
|
|
||||||
void _attach(_ScrollablePositionedListState scrollableListState) {
|
void _attach(_ScrollablePositionedListState scrollableListState) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue