Skip to content

Commit

Permalink
fix: find getting focus unexpectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
richardshiue committed Feb 7, 2025
1 parent b689a75 commit 70d6b76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>

/// handle hardware keyboard
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
print(node.hasPrimaryFocus);
if ((event is! KeyDownEvent && event is! KeyRepeatEvent) ||
!enableShortcuts) {
if (textInputService.composingTextRange != TextRange.empty) {
Expand Down Expand Up @@ -179,13 +180,6 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
}

void _onSelectionChanged() {
final doNotAttach = editorState
.selectionExtraInfo?[selectionExtraInfoDoNotAttachTextService];
if (doNotAttach == true) {
return;
}

// attach the delta text input service if needed
final selection = editorState.selection;

// if (PlatformExtension.isMobile && previousSelection == selection) {
Expand All @@ -198,13 +192,21 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
if (selection == null) {
textInputService.close();
} else {
// For the deletion, we should attach the text input service immediately.
_attachTextInputService(selection);
_updateCaretPosition(selection);

if (editorState.selectionUpdateReason == SelectionUpdateReason.uiEvent) {
focusNode.requestFocus();
AppFlowyEditorLog.editor.debug('keyboard service - request focus');
// For the deletion, we should attach the text input service immediately.
final attachTextService = editorState
.selectionExtraInfo?[selectionExtraInfoDoNotAttachTextService] ==
true;
final isUiEvent =
editorState.selectionUpdateReason == SelectionUpdateReason.uiEvent;

if (attachTextService) {
_attachTextInputService(selection);
if (isUiEvent) {
focusNode.requestFocus();
AppFlowyEditorLog.editor.debug('keyboard service - request focus');
}
} else {
AppFlowyEditorLog.editor.debug(
'keyboard service - selection changed: $selection',
Expand Down
5 changes: 5 additions & 0 deletions lib/src/editor/find_replace_menu/search_service_v3.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/find_replace_menu/search_algorithm.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

const selectionExtraInfoDisableToolbar = 'selectionExtraInfoDisableToolbar';

Expand Down Expand Up @@ -113,6 +114,9 @@ class SearchServiceV3 {
editorState.updateSelectionWithReason(
null,
reason: SelectionUpdateReason.searchHighlight,
extraInfo: {
selectionExtraInfoDoNotAttachTextService: true,
},
);
} else {
selectedIndex = selectedIndex;
Expand Down Expand Up @@ -158,6 +162,7 @@ class SearchServiceV3 {
reason: SelectionUpdateReason.searchHighlight,
extraInfo: {
selectionExtraInfoDisableToolbar: true,
selectionExtraInfoDoNotAttachTextService: true,
},
);
}
Expand Down

0 comments on commit 70d6b76

Please sign in to comment.