fix can not copy content of new inserted mention
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
export default function (range = null, type, attrs = {}) {
|
export default function (range = null, type, content = []) {
|
||||||
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 +10,7 @@ export default function (range = null, type, attrs = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
dispatch(state.tr.replaceWith(from, to, type.create(attrs)))
|
dispatch(state.tr.replaceWith(from, to, content))
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ export default class Mention extends Node {
|
|||||||
return dom.innerText.split(this.options.matcher.char).join('')
|
return dom.innerText.split(this.options.matcher.char).join('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createFragment(schema, label) {
|
||||||
|
return Fragment.fromJSON(schema, [{ type: 'text', text: `${this.options.matcher.char}${label}` }])
|
||||||
|
}
|
||||||
|
|
||||||
|
insertMention(range, attrs, schema) {
|
||||||
|
const nodeType = schema.nodes[this.name]
|
||||||
|
const content = nodeType.create(attrs, this.createFragment(schema, attrs.label))
|
||||||
|
return replaceText(range, nodeType, content)
|
||||||
|
}
|
||||||
|
|
||||||
get schema() {
|
get schema() {
|
||||||
return {
|
return {
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -54,10 +64,7 @@ export default class Mention extends Node {
|
|||||||
},
|
},
|
||||||
getContent: (dom, schema) => {
|
getContent: (dom, schema) => {
|
||||||
const label = this.getLabel(dom)
|
const label = this.getLabel(dom)
|
||||||
return Fragment.fromJSON(schema, [{
|
return this.createFragment(schema, label)
|
||||||
type: 'text',
|
|
||||||
text: `${this.options.matcher.char}${label}`,
|
|
||||||
}])
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -65,13 +72,13 @@ export default class Mention extends Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands({ schema }) {
|
commands({ schema }) {
|
||||||
return attrs => replaceText(null, schema.nodes[this.name], attrs)
|
return attrs => this.insertMention(null, attrs, schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
get plugins() {
|
get plugins() {
|
||||||
return [
|
return [
|
||||||
SuggestionsPlugin({
|
SuggestionsPlugin({
|
||||||
command: ({ range, attrs, schema }) => replaceText(range, schema.nodes[this.name], attrs),
|
command: ({ range, attrs, schema }) => this.insertMention(range, attrs, schema),
|
||||||
appendText: ' ',
|
appendText: ' ',
|
||||||
matcher: this.options.matcher,
|
matcher: this.options.matcher,
|
||||||
items: this.options.items,
|
items: this.options.items,
|
||||||
|
|||||||
Reference in New Issue
Block a user