feat: add setNodeSelection and setTextSelection commands
This commit is contained in:
23
packages/core/src/commands/setTextSelection.ts
Normal file
23
packages/core/src/commands/setTextSelection.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user