make current replaceText command compatible with the previous one

This commit is contained in:
Priestch
2020-10-20 23:49:19 +08:00
committed by Hans Pagel
parent a6da24a75d
commit 38ea4e6c66
2 changed files with 6 additions and 4 deletions

View File

@@ -1,4 +1,6 @@
export default function (range = null, type, content = []) { import { Fragment } from 'prosemirror-model'
export default function (range = null, type, attrs = {}, fragment = Fragment.empty) {
return (state, dispatch) => { return (state, dispatch) => {
const { $from, $to } = state.selection const { $from, $to } = state.selection
const index = $from.index() const index = $from.index()
@@ -10,7 +12,7 @@ export default function (range = null, type, content = []) {
} }
if (dispatch) { if (dispatch) {
dispatch(state.tr.replaceWith(from, to, content)) dispatch(state.tr.replaceWith(from, to, type.create(attrs, fragment)))
} }
return true return true

View File

@@ -31,8 +31,8 @@ export default class Mention extends Node {
insertMention(range, attrs, schema) { insertMention(range, attrs, schema) {
const nodeType = schema.nodes[this.name] const nodeType = schema.nodes[this.name]
const content = nodeType.create(attrs, this.createFragment(schema, attrs.label)) const nodeFragment = this.createFragment(schema, attrs.label)
return replaceText(range, nodeType, content) return replaceText(range, nodeType, attrs, nodeFragment)
} }
get schema() { get schema() {