'Confused with Tiptap editor behaviour?

I'm trying Tiptap editor and playing with some dummy code. But I'm confused with the behaviour. Could somebody please help me understand the behaviour ?

Below is the dummy code I'm trying (Below 4 cases were tried individually, just here for mentioning I'm placing them in one code block under same braces) :

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)

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source