add some more commands
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user