slatejs 里如何通过 api 选择文本范围并添加 mark

比如有一段文本:segmentfault,如何能直接通过 api 为 index 从 2 至 3 的文本(也就是 gm)加粗,不是通过光标选中 gm,而是直接通过数据模型里的 position,该如何实现?

查了一下,slate 文档里的 addMark api 不适合此场景:

addMark(key: string, value: any) => void

Add a custom property to the leaf text nodes in the current selection. If the selection is currently collapsed, the marks will be added to the editor.marks property instead, and applied when text is inserted next.

谢谢谢谢!

阅读 2.1k
1 个回答

知道了,用 Transforms.setNodes!

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题