From 9ccfa168f8336a018e5abf4c126c4864ad7e41c1 Mon Sep 17 00:00:00 2001 From: gaopeng Date: Thu, 15 Oct 2020 23:47:56 +0800 Subject: [PATCH] fix missing username when copy paragraph contains mentions --- packages/tiptap-extensions/src/nodes/Mention.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/tiptap-extensions/src/nodes/Mention.js b/packages/tiptap-extensions/src/nodes/Mention.js index 0d89251f5..380af809c 100644 --- a/packages/tiptap-extensions/src/nodes/Mention.js +++ b/packages/tiptap-extensions/src/nodes/Mention.js @@ -1,5 +1,6 @@ import { Node } from 'tiptap' import { replaceText } from 'tiptap-commands' +import { Fragment } from 'prosemirror-model' import SuggestionsPlugin from '../plugins/Suggestions' 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() { return { attrs: { @@ -28,6 +33,7 @@ export default class Mention extends Node { }, group: 'inline', inline: true, + content: 'inline*', selectable: false, atom: true, toDOM: node => [ @@ -43,9 +49,16 @@ export default class Mention extends Node { tag: 'span[data-mention-id]', getAttrs: dom => { 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 } }, + getContent: (dom, schema) => { + const label = this.getLabel(dom) + return Fragment.fromJSON(schema, [{ + type: 'text', + text: `${this.options.matcher.char}${label}`, + }]) + }, }, ], }