diff --git a/lib/src/editor/editor_component/service/keyboard_service_widget.dart b/lib/src/editor/editor_component/service/keyboard_service_widget.dart index 67893c4cc..3e1ed3b0d 100644 --- a/lib/src/editor/editor_component/service/keyboard_service_widget.dart +++ b/lib/src/editor/editor_component/service/keyboard_service_widget.dart @@ -231,9 +231,13 @@ class KeyboardServiceWidgetState extends State ); // 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. diff --git a/lib/src/service/editor_service.dart b/lib/src/service/editor_service.dart index 3405bf1bc..bc8c1f3d3 100644 --- a/lib/src/service/editor_service.dart +++ b/lib/src/service/editor_service.dart @@ -188,12 +188,14 @@ class _AppFlowyEditorState extends State { return Provider.value( value: editorState, - child: Overlay( - initialEntries: [ - OverlayEntry( - builder: (context) => services!, - ), - ], + child: FocusScope( + child: Overlay( + initialEntries: [ + OverlayEntry( + builder: (context) => services!, + ), + ], + ), ), ); } diff --git a/test/mobile/toolbar/mobile/toolbar_items/link_mobile_toolbar_item_test.dart b/test/mobile/toolbar/mobile/toolbar_items/link_mobile_toolbar_item_test.dart index 2d88fcf1a..496a381ce 100644 --- a/test/mobile/toolbar/mobile/toolbar_items/link_mobile_toolbar_item_test.dart +++ b/test/mobile/toolbar/mobile/toolbar_items/link_mobile_toolbar_item_test.dart @@ -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();