add removeMarks command

This commit is contained in:
Philipp Kühn
2020-04-10 22:34:49 +02:00
parent bd4fe7e5e3
commit 42a8f46011
3 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
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()
}