Merge pull request #860 from Priestch/main

fix missing username when copy paragraph contains mentions
This commit is contained in:
Hans Pagel 2020-10-15 21:41:34 +02:00 committed by GitHub
commit 30db1c9210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import { Node } from 'tiptap' import { Node } from 'tiptap'
import { replaceText } from 'tiptap-commands' import { replaceText } from 'tiptap-commands'
import { Fragment } from 'prosemirror-model'
import SuggestionsPlugin from '../plugins/Suggestions' import SuggestionsPlugin from '../plugins/Suggestions'
export default class Mention extends Node { export default class Mention extends Node {
@ -20,6 +21,10 @@ export default class Mention extends Node {
} }
} }
getLabel(dom) {
return dom.innerText.split(this.options.matcher.char).join('')
}
get schema() { get schema() {
return { return {
attrs: { attrs: {
@ -28,6 +33,7 @@ export default class Mention extends Node {
}, },
group: 'inline', group: 'inline',
inline: true, inline: true,
content: 'inline*',
selectable: false, selectable: false,
atom: true, atom: true,
toDOM: node => [ toDOM: node => [
@ -43,9 +49,16 @@ export default class Mention extends Node {
tag: 'span[data-mention-id]', tag: 'span[data-mention-id]',
getAttrs: dom => { getAttrs: dom => {
const id = dom.getAttribute('data-mention-id') const id = dom.getAttribute('data-mention-id')
const label = dom.innerText.split(this.options.matcher.char).join('') const label = this.getLabel(dom)
return { id, label } return { id, label }
}, },
getContent: (dom, schema) => {
const label = this.getLabel(dom)
return Fragment.fromJSON(schema, [{
type: 'text',
text: `${this.options.matcher.char}${label}`,
}])
},
}, },
], ],
} }