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,4 +1,4 @@
import { Editor } from '../Editor'
import { Command } from '../Editor'
import { MarkType } from 'prosemirror-model'
import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange'
@@ -6,7 +6,7 @@ import getMarkRange from '../utils/getMarkRange'
type UpdateMarkCommand = (
typeOrName: string | MarkType,
attrs: {},
) => Editor
) => Command
declare module '../Editor' {
interface Editor {
@@ -14,11 +14,10 @@ declare module '../Editor' {
}
}
export default (next: Function, editor: Editor) => (typeOrName: string | MarkType, attrs = {}) => {
const { view, state, schema } = editor
const { tr, selection, doc } = state
export const updateMark: UpdateMarkCommand = (typeOrName, attrs = {}) => ({ tr, state }) => {
const { selection, doc } = tr
let { from, to, $from, empty } = selection
const type = getMarkType(typeOrName, schema)
const type = getMarkType(typeOrName, state.schema)
if (empty) {
const range = getMarkRange($from, type)
@@ -36,6 +35,6 @@ export default (next: Function, editor: Editor) => (typeOrName: string | MarkTyp
}
tr.addMark(from, to, type.create(attrs))
view.dispatch(tr)
next()
return true
}