From 99601c7b1dc3f62d0525d7a820e4140da6a6d24b Mon Sep 17 00:00:00 2001 From: Angelo Silvestre Date: Sat, 18 Jan 2025 14:25:41 -0300 Subject: [PATCH] [SuperEditor][web] Fix double tap closing the IME connection on Safari/Firefox (Resolves #2513) --- .../src/default_editor/document_gestures_mouse.dart | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/super_editor/lib/src/default_editor/document_gestures_mouse.dart b/super_editor/lib/src/default_editor/document_gestures_mouse.dart index 5df60030e..4bd106377 100644 --- a/super_editor/lib/src/default_editor/document_gestures_mouse.dart +++ b/super_editor/lib/src/default_editor/document_gestures_mouse.dart @@ -364,10 +364,10 @@ class _DocumentMouseInteractorState extends State with } _selectionType = SelectionType.word; - _clearSelection(); + bool didSelectContent = false; if (docPosition != null) { - bool didSelectContent = _selectWordAt( + didSelectContent = _selectWordAt( docPosition: docPosition, docLayout: _docLayout, ); @@ -389,6 +389,15 @@ class _DocumentMouseInteractorState extends State with } } + // Only clear the existing selection if we were not able to place a new selection, + // because clearing the selection might close the IME connection, depending + // on the `SuperEditorImePolicies` used. If we cleared the selection and then + // placed a new selection, the IME connection would be closed and then immediately + // reopened, and this doesn't seem to work on Safari and Firefox. + if (!didSelectContent) { + _clearSelection(); + } + _focusNode.requestFocus(); }