比如有一段文本: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.
谢谢谢谢!
知道了,用
Transforms.setNodes
!