Skip to content

Commit

Permalink
feat: support mobile drag selection (#209)
Browse files Browse the repository at this point in the history
* feat: add handler for mobile selection widget

* feat: support dragging handler to update selection

* chore: format code

* feat: support dragging the cursor on mobile platform

* feat: optimize the scroll service
  • Loading branch information
LucasXu0 authored Jun 20, 2023
1 parent b298ceb commit 6e79060
Show file tree
Hide file tree
Showing 9 changed files with 501 additions and 283 deletions.
14 changes: 9 additions & 5 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
extendBodyBehindAppBar: true,
extendBodyBehindAppBar: PlatformExtension.isDesktopOrWeb,
drawer: _buildDrawer(context),
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text('AppFlowy Editor'),
),
body: SafeArea(child: _buildBody(context)),
floatingActionButton: _buildFloatingActionButton(context),
floatingActionButtonLocation: PlatformExtension.isMobile
? FloatingActionButtonLocation.startTop
: FloatingActionButtonLocation.endFloat,
floatingActionButton: PlatformExtension.isDesktopOrWeb
? _buildFloatingActionButton(context)
: null,
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
);
}

Expand Down
6 changes: 5 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const MaterialApp(
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
Expand All @@ -24,6 +24,10 @@ class MyApp extends StatelessWidget {
supportedLocales: [Locale('en', 'US')],
debugShowCheckedModeBanner: false,
home: MyHomePage(title: 'AppFlowyEditor Example'),
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,6 @@ class _DesktopSelectionServiceWidgetState
);
}

@override
List<Node> getNodesInSelection(Selection selection) {
final start =
selection.isBackward ? selection.start.path : selection.end.path;
final end =
selection.isBackward ? selection.end.path : selection.start.path;
assert(start <= end);
final startNode = editorState.document.nodeAtPath(start);
final endNode = editorState.document.nodeAtPath(end);
if (startNode != null && endNode != null) {
final nodes = NodeIterator(
document: editorState.document,
startNode: startNode,
endNode: endNode,
).toList();
if (selection.isBackward) {
return nodes;
} else {
return nodes.reversed.toList(growable: false);
}
}
return [];
}

@override
void updateSelection(Selection? selection) {
if (currentSelection.value == selection) {
Expand Down Expand Up @@ -352,7 +328,7 @@ class _DesktopSelectionServiceWidgetState

void _updateBlockSelectionAreas(Selection selection) {
assert(editorState.selectionType == SelectionType.block);
final nodes = getNodesInSelection(selection).normalized;
final nodes = editorState.getNodesInSelection(selection).normalized;

currentSelectedNodes = nodes;

Expand Down Expand Up @@ -383,7 +359,7 @@ class _DesktopSelectionServiceWidgetState
}

void _updateSelectionAreas(Selection selection) {
final nodes = getNodesInSelection(selection);
final nodes = editorState.getNodesInSelection(selection);

currentSelectedNodes = nodes;

Expand Down
Loading

0 comments on commit 6e79060

Please sign in to comment.