探索 Tiptap V3 的最新功能

聚焦命令

此命令将焦点重新设置到编辑器。

当用户点击编辑器外部的按钮时,浏览器将焦点设置到该按钮。在大多数情况下,您会希望再一次将焦点设置到编辑器。这就是为什么您在这里的几乎每个示例中都会看到这一点。

另见: setTextSelection, blur

参数

position: 'start' | 'end' | 'all' | number | boolean | null (false)

默认情况下,它会恢复光标位置(和文本选中)。传递一个位置以移动光标。

options: { scrollIntoView: boolean }

定义在聚焦时是否滚动到光标。默认为 true

使用聚焦命令

// 将焦点设置到编辑器
editor.commands.focus()

// 将光标设置到第一个位置
editor.commands.focus('start')

// 将光标设置到最后一个位置
editor.commands.focus('end')

// 选择整个文档
editor.commands.focus('all')

// 将光标设置到位置 10
editor.commands.focus(10)