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

31 lines
568 B
TypeScript
Raw Normal View History

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