1

我正在尝试 Tiptap 编辑器并使用一些虚拟代码。但我对这种行为感到困惑。有人可以帮我理解这种行为吗?

下面是我正在尝试的虚拟代码(以下 4 个案例是单独尝试的,只是在这里提到我将它们放在同一个大括号下的一个代码块中):

const customCommand = () => ({commands, state, editor}) => {

// Doesn't work. Parent node doesn't change
console.log('current node ', state.selection.from)
commands.selectParentNode()
console.log('parent node ', state.selection.from)

// Doesn't work. Parent node doesn't change
console.log('current node ', state.selection.from)
this.editor.commands.selectParentNode()
console.log('parent node ', state.selection.from)

// Doesn't work. Parent node doesn't change
console.log('current node ', this.editor.view.state.selection.from)
commands.selectParentNode()
console.log('parent node ', this.editor.view.state.selection.from)

// Works. Parent Node changes.
console.log('current node ', this.editor.view.state.selection.from)
editor.commands.selectParentNode()
console.log('parent node ', this.editor.view.state.selection.from)

}
4

0 回答 0