From 42866e105702a91007f77afd6de5140c788013ad Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 29 Aug 2022 12:10:57 +0800 Subject: [PATCH] fix: The cursor will not disappear after clicking in an area outside the editor. --- .../lib/src/service/keyboard_service.dart | 4 ++++ .../lib/src/service/selection_service.dart | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/keyboard_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/keyboard_service.dart index 1867574993..dee3f42725 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/keyboard_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/keyboard_service.dart @@ -129,6 +129,10 @@ class _AppFlowyKeyboardState extends State void _onFocusChange(bool value) { Log.keyboard.debug('on keyboard event focus change $value'); + isFocus = value; + if (!value) { + widget.editorState.service.selectionService.clearCursor(); + } } KeyEventResult _onKey(FocusNode node, RawKeyEvent event) { diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection_service.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection_service.dart index c5e351059c..6f6897596f 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection_service.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/selection_service.dart @@ -57,6 +57,9 @@ abstract class AppFlowySelectionService { /// Clears the selection area, cursor area and the popup list area. void clearSelection(); + /// Clears the cursor area. + void clearCursor(); + /// Returns the [Node]s in [Selection]. List getNodesInSelection(Selection selection); @@ -205,16 +208,23 @@ class _AppFlowySelectionState extends State currentSelectedNodes = []; currentSelection.value = null; + clearCursor(); // clear selection areas _selectionAreas ..forEach((overlay) => overlay.remove()) ..clear(); // clear cursor areas + + // hide toolbar + editorState.service.toolbarService?.hide(); + } + + @override + void clearCursor() { + // clear cursor areas _cursorAreas ..forEach((overlay) => overlay.remove()) ..clear(); - // hide toolbar - editorState.service.toolbarService?.hide(); } @override