-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Retain editor selection when using ReactEditor.focus() #5516
Conversation
🦋 Changeset detectedLatest commit: bcc4085 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have mild concerns this could break something else, but let's give it a try. Thanks!
From this change, any The workaround is to use 2023-10-04.at.09.55.30.mp4We need to either fix it so it can resolve the DOM node, or revert this @josephmr |
Is it possible we could add an option to I don't think resolving the DOM node immediately after a transform is possible, since the DOM node you're trying to select hasn't been rendered to React yet. |
This change seems to break a lot of our tests, unfortunately. What about something like this at the beginning of the static focus method: focus: editor => {
// If the editor has pending operations, focus should be requested
// after those changes are applied. Retry in the next tick.
if (editor.operations.length > 0) {
setTimeout(() => {
ReactEditor.focus(editor)
})
return
}
// ...the rest of the focus code
} |
@dylans @josephmr Many consumers having issues from that release udecode/plate#2674. We should release @skogsmaskin's suggestion as a quick fix. |
I drafted a PR with my suggestion here - #5527 I haven't been able to confirm if this will actually fix your particular issue @zbeyens would you be able to confirm? I'm not even sure if this is the right solution, but to me, it sounds like a good idea to not interfere with document selections, while the ReactEditor might potentially try to create a new one through transforms. This does at least fix very similar issues we have been troubled with in our code. |
There seems to be a similar issue with the There it's also trying to map a DOM node with this function: |
This change is also breaking our tests, slate is unable to resolve node on focus call.
|
I am having the same issue since this PR was merged. When I try to set a link with a selection active.
|
I opened up a PR today, which should fix the |
Description
When calling
ReactEditor.focus()
the current editor selection is lost and the caret is placed at the beginning of the document. This change retains the current editor selection when giving the editor focus.Issue
Fixes: (link to issue)
Example
Before:
Screen.Recording.2023-09-21.at.11.51.59.AM.mov
After:
Screen.Recording.2023-09-21.at.11.49.03.AM.mov
Context
Before focusing the editor we set the DOM selection so that the corresponding
onDOMSelectionChange
handler ineditable.tsx
does not reset the editor selection when it fires after theel.focus()
call.Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)