Skip to content

Commit 7120ea1

Browse files
angelosilvestrematthew-carroll
authored andcommitted
[DemoApp] - Fix editor not re-gaining focus when the app is brought to foreground (Resolves #2279) (#2496)
1 parent 95b760a commit 7120ea1

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

super_editor/example/lib/demos/example_editor/example_editor.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,16 @@ class _ExampleEditorState extends State<ExampleEditor> {
170170
// I tried explicitly unfocus()'ing the URL textfield
171171
// in the toolbar but it didn't return focus to the
172172
// editor. I'm not sure why.
173-
_editorFocusNode.requestFocus();
173+
//
174+
// Only do that if the primary focus is not at the root focus scope because
175+
// this might signify that the app is going to the background. Removing
176+
// the focus from the root focus scope in that situation prevents the editor
177+
// from re-gaining focus when the app is brought back to the foreground.
178+
//
179+
// See https://github.com/superlistapp/super_editor/issues/2279 for details.
180+
if (FocusManager.instance.primaryFocus != FocusManager.instance.rootScope) {
181+
_editorFocusNode.requestFocus();
182+
}
174183
}
175184

176185
DocumentGestureMode get _gestureMode {
@@ -252,7 +261,16 @@ class _ExampleEditorState extends State<ExampleEditor> {
252261
_imageFormatBarOverlayController.hide();
253262

254263
// Ensure that focus returns to the editor.
255-
_editorFocusNode.requestFocus();
264+
//
265+
// Only do that if the primary focus is not at the root focus scope because
266+
// this might signify that the app is going to the background. Removing
267+
// the focus from the root focus scope in that situation prevents the editor
268+
// from re-gaining focus when the app is brought back to the foreground.
269+
//
270+
// See https://github.com/superlistapp/super_editor/issues/2279 for details.
271+
if (FocusManager.instance.primaryFocus != FocusManager.instance.rootScope) {
272+
_editorFocusNode.requestFocus();
273+
}
256274
}
257275

258276
@override

website/lib/homepage/featured_editor.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,16 @@ class _FeaturedEditorState extends State<FeaturedEditor> {
9191
// I tried explicitly unfocus()'ing the URL textfield
9292
// in the toolbar but it didn't return focus to the
9393
// editor. I'm not sure why.
94-
_editorFocusNode.requestFocus();
94+
//
95+
// Only do that if the primary focus is not at the root focus scope because
96+
// this might signify that the app is going to the background. Removing
97+
// the focus from the root focus scope in that situation prevents the editor
98+
// from re-gaining focus when the app is brought back to the foreground.
99+
//
100+
// See https://github.com/superlistapp/super_editor/issues/2279 for details.
101+
if (FocusManager.instance.primaryFocus != FocusManager.instance.rootScope) {
102+
_editorFocusNode.requestFocus();
103+
}
95104
}
96105

97106
void _onDocumentChange(_) {

0 commit comments

Comments
 (0)