Files
tiptap/packages/core/src/commands/unsetAllMarks.ts
Philipp Kühn ca8d1a4245 add command scope
2021-02-16 11:27:58 +01:00

32 lines
613 B
TypeScript

import { Command, Commands } from '../types'
declare module '@tiptap/core' {
interface AllCommands {
unsetAllMarks: {
/**
* Remove all marks in the current selection.
*/
unsetAllMarks: () => Command,
}
}
}
export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
const { selection } = tr
const { from, to, empty } = selection
if (empty) {
return true
}
if (dispatch) {
Object
.entries(state.schema.marks)
.forEach(([, mark]) => {
tr.removeMark(from, to, mark as any)
})
}
return true
}