Skip to content

Commit

Permalink
feat: clear selection when losing focus
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jun 14, 2023
1 parent dd3fa21 commit 03f5c08
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,13 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
);

// clear the selection when the focus is lost.
// if (!focusNode.hasFocus) {
// editorState.selection = null;
// }
if (PlatformExtension.isDesktop && !focusNode.hasFocus) {
final children =
WidgetsBinding.instance.focusManager.primaryFocus?.children;
if (children != null && !children.contains(focusNode)) {
editorState.selection = null;
}
}
}

// only verify on macOS.
Expand Down
14 changes: 8 additions & 6 deletions lib/src/service/editor_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ class _AppFlowyEditorState extends State<AppFlowyEditor> {

return Provider.value(
value: editorState,
child: Overlay(
initialEntries: [
OverlayEntry(
builder: (context) => services!,
),
],
child: FocusScope(
child: Overlay(
initialEntries: [
OverlayEntry(
builder: (context) => services!,
),
],
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import '../test_helpers/mobile_app_with_toolbar_widget.dart';

void main() {
testWidgets('linkMobileToolbarItem', (WidgetTester tester) async {
if (PlatformExtension.isDesktopOrWeb) {
return;
}

const text = 'Welcome to Appflowy 😁';
final editor = tester.editor..addParagraphs(3, initialText: text);
await editor.startTesting();
Expand Down

0 comments on commit 03f5c08

Please sign in to comment.