-
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
ReactEditor.focus does not work after inserting a new node #4961
Comments
As the newest version has a bug preventing to focus editor after inserting a new node. See ianstormtaylor/slate#4961
Change to
|
@ryanmitts That doesn't work for me. My issue is related, and what I want to do is even simpler -- Move the cursor the end of the document. |
@Nikhil22 How about |
I seem to have maybe potentially found the fix for this. Here's what I understood the problem to be: essentially, if the place that I clicked on was not directly the editor, then it lost focus (i.e. ReactEditor.isFocused() was false), but if you try to refocus it, it gave me error "Cannot resolve a DOM node from Slate node: undefined" -- which meant, yeah: if the v0.77 isn't adding the slate node after the Transforms.insertNodes then this'd be a problem. How I created a slate node
You'll get your selection. Here's the code, when I was adding a new paragraph after the one I was on (i.e. if I was on [0, 0, 16]--in the middle of a para), I wanted to create [0,1] and jump to [0,1,0]):
|
How is this still an unresolved issue? if there's a function for ".focus" it shouldn't require workarounds. Seems like a pretty crucial function, considering people are constantly clicking on format buttons and thus blurring the editor. |
this! |
const end = Editor.end(editor, []); deselect first and then select, works for me |
This is hacky as hell but I was working with a web view and it really was not wanting to focus, I essentially created a listener that kept track of the last focused input element, then to focus at a given point I focused the last element and then used @gaoqs solution. This very hacky manual focusing of the page I believe is only needed do to the web view losing focus. |
Description
When using
ReactEditor.focus
after inserting a new Node viaTransforms.insertNodes
, the mouse cursor is not placed at the expected location.Recording
Focusing works in
[email protected]
and before:Focusing no longer works in
[email protected]
Sandbox
[email protected] and before: https://codesandbox.io/s/elastic-nova-2nw62t?file=/src/App.js
[email protected]: https://codesandbox.io/s/suspicious-mestorf-e9306h?file=/src/App.js
The sandboxes are based on the Mentions example: https://github.com/ianstormtaylor/slate/blob/main/site/examples/mentions.tsx
Steps
To reproduce the behavior:
Expectation
The cursor should be placed at the end of the text in the editor.
Environment
The text was updated successfully, but these errors were encountered: