Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mobile selection scroll should work on both side #220

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/editor_component/service/scroll/auto_scroller.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -49,9 +50,9 @@ class _AutoScrollableWidgetState extends State<AutoScrollableWidget> {
void _initAutoScroller() {
_autoScroller = AutoScroller(
_scrollableState,
velocityScalar: 15,
velocityScalar: PlatformExtension.isDesktopOrWeb ? 15 : 100,
onScrollViewScrolled: () {
_autoScroller.continueToAutoScroll();
// _autoScroller.continueToAutoScroll();
},
);
}
Expand Down
12 changes: 10 additions & 2 deletions lib/src/editor/editor_component/service/scroll_service_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,22 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
editorState.selectionUpdateReason == SelectionUpdateReason.selectAll) {
return;
}
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
final selectionRect = editorState.selectionRects();
if (selectionRect.isEmpty) {
return;
}
final endTouchPoint = selectionRect.last.centerRight;
if (selection.isCollapsed) {
startAutoScroll(endTouchPoint, edgeOffset: 50);
if (PlatformExtension.isMobile) {
// soft keyboard
// workaround: wait for the soft keyboard to show up
Future.delayed(const Duration(milliseconds: 300), () {
startAutoScroll(endTouchPoint, edgeOffset: 50);
});
} else {
startAutoScroll(endTouchPoint, edgeOffset: 50);
}
} else {
startAutoScroll(endTouchPoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class _MobileSelectionServiceWidgetState
/// Pan
Offset? _panStartOffset;
double? _panStartScrollDy;
Selection? _panStartSelection;

MobileSelectionDragMode dragMode = MobileSelectionDragMode.none;

Expand Down Expand Up @@ -274,6 +275,7 @@ class _MobileSelectionServiceWidgetState

final position = details.globalPosition;
final selection = editorState.selection;
_panStartSelection = selection;
if (selection == null) {
dragMode = MobileSelectionDragMode.none;
} else if (selection.isCollapsed &&
Expand Down Expand Up @@ -322,7 +324,10 @@ class _MobileSelectionServiceWidgetState
if (end != null) {
if (dragMode == MobileSelectionDragMode.leftSelectionHandler) {
updateSelection(
selection.copyWith(start: end),
selection.copyWith(
end: end,
start: _panStartSelection?.normalized.end,
),
);
} else if (dragMode == MobileSelectionDragMode.rightSelectionHandler) {
updateSelection(
Expand Down