Skip to content

Commit 14aa68e

Browse files
Fix nuanced SuperIme issue where Flutter reports IME closure to us, but we weren't releasing it, which caused the keyboard to never be able to come back up after it closes.
1 parent e2e9d00 commit 14aa68e

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

super_editor/example_chat/lib/floating_chat_editor_demo/floating_chat_editor_demo_configured.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _FloatingChatEditorBuilderDemoState extends State<FloatingChatEditorBuilde
6969
pageBuilder: (context, pageGeometry) {
7070
return _ChatPage(
7171
appBar: _buildAppBar(),
72-
scrollPadding: EdgeInsets.only(bottom: pageGeometry.bottomSafeArea),
72+
scrollPadding: EdgeInsets.only(bottom: pageGeometry.bottomSafeArea ?? 0),
7373
);
7474
},
7575
editorSheet: _buildEditorSheet(),

super_editor/lib/src/default_editor/document_ime/document_ime_communication.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class DocumentImeInputClient extends TextInputConnectionDecorator with TextInput
2626
required this.textDeltasDocumentEditor,
2727
required this.imeConnection,
2828
required this.onPerformSelector,
29+
required this.onImeConnectionClosed,
2930
this.floatingCursorController,
3031
}) : super(imeConnection.value) {
3132
// Note: we don't listen to document changes because we expect that any change during IME
@@ -65,6 +66,20 @@ class DocumentImeInputClient extends TextInputConnectionDecorator with TextInput
6566
/// For the list of selectors, see [MacOsSelectors].
6667
final void Function(String selectorName) onPerformSelector;
6768

69+
/// Callback invoked when Flutter's IME system tells us that our connection
70+
/// was closed.
71+
///
72+
/// The owner of this client should update any references to reflect that an IME
73+
/// connection is no longer available. If the IME connection came from `SuperIme`
74+
/// then the owner of this client should release the shared IME. Failure to do this
75+
/// can lead to buggy keyboard behavior with the following order of events:
76+
///
77+
/// 1. Open an IME connection, show the keyboard
78+
/// 2. Something causes the IME connection to close, which also closes the keyboard
79+
/// 3. **You don't release the connection**
80+
/// 4. You try to open the keyboard (using the existing connection) but nothing happens.
81+
final VoidCallback onImeConnectionClosed;
82+
6883
// TODO: get floating cursor out of here. Use a multi-client IME decorator to split responsibilities
6984
late FloatingCursorController? floatingCursorController;
7085

super_editor/lib/src/default_editor/document_ime/shared_ime.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class SuperIme with ChangeNotifier {
9595
return;
9696
}
9797

98-
if (false == _imeConnection?.attached) {
98+
if (_imeConnection != null && _imeConnection!.attached == false) {
9999
// We have a connection, but its been detached, and we can't re-attach
100100
// without creating a new connection. Throw it away.
101101
//

super_editor/lib/src/default_editor/document_ime/supereditor_ime_interactor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ class SuperEditorImeInteractorState extends State<SuperEditorImeInteractor> impl
408408
onPerformAction: (action) => _imeClient.performAction(action),
409409
),
410410
imeConnection: _ownedImeConnection,
411+
onImeConnectionClosed: () => SuperIme.instance.releaseOwnership(_myImeId),
411412
onPerformSelector: _onPerformSelector,
412413
);
413414
}

0 commit comments

Comments
 (0)