diff --git a/super_editor/example/lib/demos/example_editor/example_editor.dart b/super_editor/example/lib/demos/example_editor/example_editor.dart index b11549763..54445d17c 100644 --- a/super_editor/example/lib/demos/example_editor/example_editor.dart +++ b/super_editor/example/lib/demos/example_editor/example_editor.dart @@ -170,7 +170,16 @@ class _ExampleEditorState extends State { // I tried explicitly unfocus()'ing the URL textfield // in the toolbar but it didn't return focus to the // editor. I'm not sure why. - _editorFocusNode.requestFocus(); + // + // Only do that if the primary focus is not at the root focus scope because + // this might signify that the app is going to the background. Removing + // the focus from the root focus scope in that situation prevents the editor + // from re-gaining focus when the app is brought back to the foreground. + // + // See https://github.com/superlistapp/super_editor/issues/2279 for details. + if (FocusManager.instance.primaryFocus != FocusManager.instance.rootScope) { + _editorFocusNode.requestFocus(); + } } DocumentGestureMode get _gestureMode { @@ -252,7 +261,16 @@ class _ExampleEditorState extends State { _imageFormatBarOverlayController.hide(); // Ensure that focus returns to the editor. - _editorFocusNode.requestFocus(); + // + // Only do that if the primary focus is not at the root focus scope because + // this might signify that the app is going to the background. Removing + // the focus from the root focus scope in that situation prevents the editor + // from re-gaining focus when the app is brought back to the foreground. + // + // See https://github.com/superlistapp/super_editor/issues/2279 for details. + if (FocusManager.instance.primaryFocus != FocusManager.instance.rootScope) { + _editorFocusNode.requestFocus(); + } } @override diff --git a/website/lib/homepage/featured_editor.dart b/website/lib/homepage/featured_editor.dart index b96c51d72..ab2472122 100644 --- a/website/lib/homepage/featured_editor.dart +++ b/website/lib/homepage/featured_editor.dart @@ -91,7 +91,16 @@ class _FeaturedEditorState extends State { // I tried explicitly unfocus()'ing the URL textfield // in the toolbar but it didn't return focus to the // editor. I'm not sure why. - _editorFocusNode.requestFocus(); + // + // Only do that if the primary focus is not at the root focus scope because + // this might signify that the app is going to the background. Removing + // the focus from the root focus scope in that situation prevents the editor + // from re-gaining focus when the app is brought back to the foreground. + // + // See https://github.com/superlistapp/super_editor/issues/2279 for details. + if (FocusManager.instance.primaryFocus != FocusManager.instance.rootScope) { + _editorFocusNode.requestFocus(); + } } void _onDocumentChange(_) {