mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-06 02:17:49 +08:00
fix: can not write second mention bug, see #874
This commit is contained in:
parent
38ea4e6c66
commit
046babfd3a
@ -43,7 +43,7 @@ export default class Mention extends Node {
|
|||||||
},
|
},
|
||||||
group: 'inline',
|
group: 'inline',
|
||||||
inline: true,
|
inline: true,
|
||||||
content: 'inline*',
|
content: 'text*',
|
||||||
selectable: false,
|
selectable: false,
|
||||||
atom: true,
|
atom: true,
|
||||||
toDOM: node => [
|
toDOM: node => [
|
||||||
|
@ -2,6 +2,37 @@ import { Plugin, PluginKey } from 'prosemirror-state'
|
|||||||
import { Decoration, DecorationSet } from 'prosemirror-view'
|
import { Decoration, DecorationSet } from 'prosemirror-view'
|
||||||
import { insertText } from 'tiptap-commands'
|
import { insertText } from 'tiptap-commands'
|
||||||
|
|
||||||
|
function getTextBetween(node, from, to, blockSeparator, inlineSeparator, leafText = '\0') {
|
||||||
|
let text = ''
|
||||||
|
let blockSeparated = true
|
||||||
|
let inlineNode = null
|
||||||
|
node.content.nodesBetween(from, to, (innerNode, pos) => {
|
||||||
|
if (innerNode.isText) {
|
||||||
|
if (inlineNode) {
|
||||||
|
inlineNode = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
text += innerNode.text.slice(Math.max(from, pos) - pos, to - pos)
|
||||||
|
blockSeparated = !blockSeparator
|
||||||
|
} else if (innerNode.isLeaf && leafText) {
|
||||||
|
text += leafText
|
||||||
|
blockSeparated = !blockSeparator
|
||||||
|
} else if (innerNode.isInline && !innerNode.isLeaf) {
|
||||||
|
text += inlineSeparator
|
||||||
|
if (innerNode.textContent) {
|
||||||
|
text += innerNode.textContent
|
||||||
|
inlineNode = innerNode
|
||||||
|
}
|
||||||
|
text += inlineSeparator
|
||||||
|
blockSeparated = !blockSeparated
|
||||||
|
} else if (!blockSeparated && innerNode.isBlock) {
|
||||||
|
text += blockSeparator
|
||||||
|
blockSeparated = true
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
// Create a matcher that matches when a specific character is typed. Useful for @mentions and #tags.
|
// Create a matcher that matches when a specific character is typed. Useful for @mentions and #tags.
|
||||||
function triggerCharacter({
|
function triggerCharacter({
|
||||||
char = '@',
|
char = '@',
|
||||||
@ -26,7 +57,7 @@ function triggerCharacter({
|
|||||||
// Lookup the boundaries of the current node
|
// Lookup the boundaries of the current node
|
||||||
const textFrom = $position.before()
|
const textFrom = $position.before()
|
||||||
const textTo = $position.end()
|
const textTo = $position.end()
|
||||||
const text = $position.doc.textBetween(textFrom, textTo, '\0', '\0')
|
const text = getTextBetween($position.doc, textFrom, textTo, '\0', '\0')
|
||||||
|
|
||||||
let match = regexp.exec(text)
|
let match = regexp.exec(text)
|
||||||
let position
|
let position
|
||||||
|
Loading…
Reference in New Issue
Block a user