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

29 lines
539 B
TypeScript
Raw Normal View History

2020-04-11 04:34:49 +08:00
import { Editor } from '../Editor'
declare module '../Editor' {
interface Editor {
removeMarks(): Editor,
}
}
export default function removeMarks(next: Function, editor: Editor): void {
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()
}