项目

tiptap 聚焦命令

这个命令将焦点重新设置到编辑器上。

当用户点击编辑器外的按钮时,浏览器会将焦点切换到该按钮。在大多数情况下,你会希望再次将焦点回到编辑器。这就是为什么在每个示例中几乎都会看到这个操作的原因。

参阅:setTextSelectionblur

参数

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);
在本文档中