Skip to content
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

Manually handle focus interaction between Flutter and CodeMirror #2920

Merged
merged 4 commits into from
Apr 1, 2024

Conversation

parlough
Copy link
Member

@parlough parlough commented Mar 29, 2024

I'm not sure if this is the best or correct solution, but I tried out the following to prevent focus from being shared and enabling tab to work in the CodeMirror editor. I added Esc and Shift+Esc to escape the editor, but perhaps there's something more standard?

Let me know what you think of both the implementation and the behavior. Thanks!

Potentially fixes #2852

Staged: https://parlough-dart-dev.web.app/

Copy link
Member

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

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

I'm wondering whether we actually need the escape / shift-escape keybindings...

pkgs/sketch_pad/lib/editor/editor.dart Show resolved Hide resolved
}
},
shortcuts: {
// Add Esc and Shift+Esc as shortcuts for focus to leave editor.
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this? I wonder what the expectations are wrt focus traversal and text editors. I think that if the focus ever escapes the text editor, people would expect the normal focus traversal until the focus was again captured by the text editor. But do users expect to have a keybinding that lets them move the focus out of the text editor?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need some key binding like this as otherwise users have no easy way for focus traversal to escape CodeMirror with just the keyboard.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'll remove these for now, as that still leaves us in a better spot than currently, then investigate adding something like the Esc+Tab that CodeMirror 6 uses as it is likely what developers are becoming familiar with.

@devoncarew
Copy link
Member

devoncarew commented Apr 1, 2024

I think we should also make the editor area the default focus. In a Focus subclass, I believe this is the autofocus param (I have not looked to see exactly how that would apply to this PR). Or potentially, an explicit FocusScope.of(context).requestFocus() somewhere during startup.

@dgreensp
Copy link

dgreensp commented Apr 1, 2024

CodeMirror listens for "escape followed by tab" as a way to tab out of the code editor if the tab key has been bound to a command: https://codemirror.net/examples/tab/

@parlough parlough merged commit d7735f0 into main Apr 1, 2024
4 checks passed
@parlough parlough deleted the fix/focus-with-editor branch April 1, 2024 20:13
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.

Cannot focus on text after pressing TAB
3 participants