tiptap/packages/core/src/commands/deleteRange.ts

23 lines
418 B
TypeScript
Raw Normal View History

2021-02-10 16:59:35 +08:00
import { Command, Commands, Range } from '../types'
2021-01-21 19:13:20 +08:00
2021-02-11 01:05:02 +08:00
declare module '@tiptap/core' {
2021-02-16 18:27:58 +08:00
interface AllCommands {
deleteRange: {
/**
* Delete a given range.
*/
deleteRange: (range: Range) => Command,
}
2021-02-11 01:05:02 +08:00
}
}
2021-02-10 16:59:35 +08:00
export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch }) => {
2021-01-21 19:13:20 +08:00
const { from, to } = range
if (dispatch) {
tr.delete(from, to)
}
return true
}