Slatejs editor.selection 在弹出框上返回 null?

问题描述

我创建了一个带有空白的 slatejs 富文本编辑器,但我遇到了一个问题,即我在弹出框内执行操作时无法获取当前选择。但是,我在这里on sandbox重新创建了这个问题。

  • 其他信息
    • 如果您想知道我为什么要将 editor.selection 放入弹出框?我需要它,因为有时我会在弹出框内执行操作,并且需要使用 Trsnform.setNodes(editor,newData,at:{editor.selection.path})
    • 更新文档手册
  • 我的目标是在我的sandbox中获得editor.selection中的SimplePopover.tsx:64

解决方法

不久前我也遇到了同样的问题。我找到了一种解决方法,方法是将选择保存在单击按钮时的状态,并在所有操作完成后,在插入过程中使用 Transforms.select(editor,selection); Transforms.insertNodes(editor,node)

或指定位置Transforms.insertNodes(editor,node,{at:selection})