feat: add setNodeSelection and setTextSelection commands

This commit is contained in:
Philipp Kühn
2021-04-27 11:41:24 +02:00
parent fe61a6e3d8
commit 811bf693eb
7 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import { TextSelection } from 'prosemirror-state'
import { Command, RawCommands, Range } from '../types'
declare module '@tiptap/core' {
interface Commands {
setTextSelection: {
/**
* Creates a TextSelection.
*/
setTextSelection: (range: Range) => Command,
}
}
}
export const setTextSelection: RawCommands['setTextSelection'] = range => ({ tr, dispatch }) => {
if (dispatch) {
const selection = TextSelection.create(tr.doc, range.from, range.to)
tr.setSelection(selection)
}
return true
}