feat: add setNodeSelection and setTextSelection commands
This commit is contained in:
23
packages/core/src/commands/setNodeSelection.ts
Normal file
23
packages/core/src/commands/setNodeSelection.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NodeSelection } from 'prosemirror-state'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
setNodeSelection: {
|
||||
/**
|
||||
* Creates a NodeSelection.
|
||||
*/
|
||||
setNodeSelection: (position: number) => Command,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const setNodeSelection: RawCommands['setNodeSelection'] = position => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
const selection = NodeSelection.create(tr.doc, position)
|
||||
|
||||
tr.setSelection(selection)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user