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,9 +1,9 @@
import { Editor } from '../Editor'
import { Command } from '../Editor'
import { MarkType } from 'prosemirror-model'
import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange'
type RemoveMarkCommand = (typeOrName: string | MarkType) => Editor
type RemoveMarkCommand = (typeOrName: string | MarkType) => Command
declare module '../Editor' {
interface Editor {
@@ -11,10 +11,9 @@ declare module '../Editor' {
}
}
export default (next: Function, editor: Editor) => (typeOrName: string | MarkType) => {
const { view, state, schema } = editor
const { tr, selection } = state
const type = getMarkType(typeOrName, schema)
export const removeMark: RemoveMarkCommand = (typeOrName) => ({ tr, state }) => {
const { selection } = tr
const type = getMarkType(typeOrName, state.schema)
let { from, to, $from, empty } = selection
if (empty) {
@@ -27,6 +26,6 @@ export default (next: Function, editor: Editor) => (typeOrName: string | MarkTyp
}
tr.removeMark(from, to, type)
view.dispatch(tr)
next()
return true
}