探索 Tiptap V3 的最新功能

setTextSelection 命令

如果你在编辑器的上下文中考虑选择,你很可能会想到文本选择。通过 setTextSelection 你可以控制文本选择并将其设置为指定的范围或位置。

另见: focus, setNodeSelection, deleteSelection, selectAll

参数

position: number | Range

传入一个数字,或一个范围,例如 { from: 5, to: 10 }

使用 setTextSelection 命令

// 将光标设置到指定位置
editor.commands.setTextSelection(10)

// 将文本选择设置为指定范围
editor.commands.setTextSelection({ from: 5, to: 10 })