tiptap/packages/core/src/commands/removeMarks.ts
2020-04-21 23:22:27 +02:00

31 lines
568 B
TypeScript

import { Editor } from '../Editor'
type RemoveMarks = () => any
declare module '../Editor' {
interface Editor {
removeMarks: RemoveMarks,
}
}
export default (next: Function, editor: Editor): RemoveMarks => () => {
const { state, view, schema } = editor
const { selection, tr } = state
const { from, to, empty } = selection
let transaction = tr
if (empty) {
next()
return
}
Object
.entries(schema.marks)
.forEach(([name, mark]) => {
transaction.removeMark(from, to, mark)
})
view.dispatch(transaction)
next()
}