Skip to content

Avoid focus ping pong between editors #2539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tjarvstrand
Copy link
Contributor

@tjarvstrand tjarvstrand commented Apr 11, 2025

In the current implementation, requestKeyboard will request focus if an editor is currently not focused.

In certain situations, there can be a delay between getting focus and executing the callback. If the editor has lost focus in that time, it will try to steal it back. This is in itself not great, but what's worse is that if you have more than one editor and switch between them rapidly, you can end up in a state where one editor is constantly trying to steal the focus back from the other, ending up in a ping pong situation that freezes the entire app.

Description

This PR moves the call to requestFocus out of requestKeyboard, so that it can instead be requested separately in the places where it's needed.

Related Issues

Type of Change

  • Feature: New functionality without breaking existing features.
  • 🛠️ Bug fix: Resolves an issue without altering current behavior.
  • 🧹 Refactor: Code reorganization, no behavior change.
  • Breaking: Alters existing functionality and requires updates.
  • 🧪 Tests: New or modified tests
  • 📝 Documentation: Updates or additions to documentation.
  • 🗑️ Chore: Routine tasks, or maintenance.
  • Build configuration change: Build/configuration changes.

@tjarvstrand tjarvstrand force-pushed the avoid-focus-pingpong branch from d27f201 to 2c93e94 Compare April 11, 2025 12:09
Comment on lines -1202 to -1203
} else {
widget.config.focusNode.requestFocus();
Copy link
Collaborator

@EchoEllet EchoEllet Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this change the behavior for QuillRawEditor or cause an issue for users who use QuillRawEditor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially.

It does not look to me as if focus would have to be requested from any of the places where QuillRawEditorState.requestKeyboard is called from within flutter-quill, but if anyone is calling that method from the outside and expecting the editor to receive focus, they will be disappointed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants