add some more commands

This commit is contained in:
Philipp Kühn
2020-09-21 23:17:30 +02:00
parent 778e064979
commit 4da71ecfbb
27 changed files with 207 additions and 210 deletions

View File

@@ -1,6 +1,6 @@
import { Editor } from '../Editor'
import { Command } from '../Editor'
type RemoveMarksCommand = () => Editor
type RemoveMarksCommand = () => Command
declare module '../Editor' {
interface Editor {
@@ -8,23 +8,19 @@ declare module '../Editor' {
}
}
export default (next: Function, editor: Editor) => () => {
const { state, view, schema } = editor
const { selection, tr } = state
export const removeMarks: RemoveMarksCommand = () => ({ tr, state }) => {
const { selection } = tr
const { from, to, empty } = selection
let transaction = tr
if (empty) {
next()
return
return true
}
Object
.entries(schema.marks)
.entries(state.schema.marks)
.forEach(([name, mark]) => {
transaction.removeMark(from, to, mark)
tr.removeMark(from, to, mark)
})
view.dispatch(transaction)
next()
return true
}