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

Use previous selection when focus origins from key event #137

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

Conversation

jnystad
Copy link

@jnystad jnystad commented Aug 10, 2022

Selection should be restored to its previous state when using tab to navigate
a page with ProseMirror and other focusable elements with selection (inputs).

This is similar to how textareas work.

Note: While it's possible to create a workaround outside of prosemirror-view by saving the selection and restoring it before/after focus, it does not seem to be a way to avoid scroll jumps when the selection is further down in the document.

The input focus handler restores the previous selection (and DOM selection) already, so ignoring focus when origin is unknown (originated outside of the editor and not via pointer click) makes it restore the previous selection correctly without causing scroll jumps.

Selection should be restored to its previous state when using tab to navigate
a page with ProseMirror and other focusable elements with selection (inputs).

This is similar to how textareas work.
marijnh added a commit that referenced this pull request Aug 12, 2022
FIX: Make sure that when the editor receives focus via tab or calling
`.focus()` on its DOM element, the existing selection is restored.

Issue #137
@marijnh
Copy link
Member

marijnh commented Aug 12, 2022

This patch seems somewhat scary, because it's hard to know that it won't incorrectly ignore selections in situations where they they are actual user actions that we somehow didn't predict. Does attached patch work for you?

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