Slatejs editor.selection returns null on popovers?

516 views Asked by At

I created a slatejs rich text editor with voids, but I have a problem which is I can't get the current selection while I am doing actions inside the popover. However, I recreated the problem here on sandbox.

  • additional info
    • if you need to know why I want to get the editor.selection inside a popover? I need that because sometimes I do actions inside the popover and I need to update the document manula using Trsnform.setNodes(editor,newData,at:{editor.selection.path})
  • my goal is to get editor.selection in SimplePopover.tsx:64 in my sandbox.
2

There are 2 answers

0
esp On

I see an error on the sandbox, but have suggestion for you, if I have understood your question correctly, the component invoking SimplePopover might be getting re-rendered, resulting in selection being lost. You can maintain that, invoke popover with it, have editor.selection = props.selection and clear selection on closing the popover.

0
newCoder On

I also ran into the same problem a while back.I found a work around to this by saving the selection in a state when the button is clicked and after everything is done, during insertion use Transforms.select(editor,selection); Transforms.insertNodes(editor,node)

or specify the location Transforms.insertNodes(editor,node,{at:selection})