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
|
||||
}
|
||||
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
|
||||
}
|
||||
@@ -34,6 +34,8 @@ import * as selectParentNode from '../commands/selectParentNode'
|
||||
import * as setContent from '../commands/setContent'
|
||||
import * as setMark from '../commands/setMark'
|
||||
import * as setNode from '../commands/setNode'
|
||||
import * as setNodeSelection from '../commands/setNodeSelection'
|
||||
import * as setTextSelection from '../commands/setTextSelection'
|
||||
import * as sinkListItem from '../commands/sinkListItem'
|
||||
import * as splitBlock from '../commands/splitBlock'
|
||||
import * as splitListItem from '../commands/splitListItem'
|
||||
@@ -84,6 +86,8 @@ export { selectParentNode }
|
||||
export { setContent }
|
||||
export { setMark }
|
||||
export { setNode }
|
||||
export { setNodeSelection }
|
||||
export { setTextSelection }
|
||||
export { sinkListItem }
|
||||
export { splitBlock }
|
||||
export { splitListItem }
|
||||
@@ -139,6 +143,8 @@ export const Commands = Extension.create({
|
||||
...setContent,
|
||||
...setMark,
|
||||
...setNode,
|
||||
...setNodeSelection,
|
||||
...setTextSelection,
|
||||
...sinkListItem,
|
||||
...splitBlock,
|
||||
...splitListItem,
|
||||
|
||||
Reference in New Issue
Block a user