Skip to content

Commit

Permalink
[DemoApp] - Fix editor not re-gaining focus when the app is brought t…
Browse files Browse the repository at this point in the history
…o foreground (Resolves #2279) (#2496)
  • Loading branch information
angelosilvestre authored Jan 10, 2025
1 parent 85a49b2 commit b1a1cf9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
22 changes: 20 additions & 2 deletions super_editor/example/lib/demos/example_editor/example_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,16 @@ class _ExampleEditorState extends State<ExampleEditor> {
// 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 {
Expand Down Expand Up @@ -252,7 +261,16 @@ class _ExampleEditorState extends State<ExampleEditor> {
_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
Expand Down
11 changes: 10 additions & 1 deletion website/lib/homepage/featured_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ class _FeaturedEditorState extends State<FeaturedEditor> {
// 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(_) {
Expand Down

0 comments on commit b1a1cf9

Please sign in to comment.