This commit is contained in:
Eric Bailey
2023-10-10 20:08:37 -05:00
parent 078ba4cd35
commit bfdf41a4c3
3 changed files with 10 additions and 11 deletions
@@ -61,7 +61,6 @@ export const TextInput = React.forwardRef(function TextInputImpl(
() => [
Document,
LinkDecorator,
// TagDecorator,
Tags.configure({
HTMLAttributes: {
class: 'inline-tag',
@@ -23,6 +23,10 @@ export function getHashtagAt(text: string, position: number) {
}
}
/*
* show autocomplete after a single # is typed
* AND the cursor is next to the #
*/
const hashRegex = /#/g
let hashMatch
while ((hashMatch = hashRegex.exec(text))) {
@@ -38,7 +42,7 @@ export function insertTagAt(text: string, position: number, tag: string) {
const target = getHashtagAt(text, position)
if (target) {
return `${text.slice(0, target.index)}#${tag} ${text.slice(
target.index + target.value.length + 1, // add 1 to include the "@"
target.index + target.value.length + 1, // add 1 to include the "#"
)}`
}
return text
@@ -1,4 +1,8 @@
/** @see https://github.com/ueberdosis/tiptap/blob/main/packages/extension-mention/src/mention.ts */
/**
* This is basically a fork of the Mention plugin from Tiptap.
*
* @see https://github.com/ueberdosis/tiptap/blob/025dfff1d9e4796edf3a451f7f53d06a07b95d69/packages/extension-mention/src/mention.ts
*/
import {mergeAttributes, Node} from '@tiptap/core'
import {Node as ProseMirrorNode} from '@tiptap/pm/model'
@@ -127,14 +131,6 @@ export const Tags = Node.create<TagOptions>({
},
renderHTML({node, HTMLAttributes}) {
console.log(
'renderText',
node,
this.options.renderLabel({
options: this.options,
node,
}),
)
return [
'span',
mergeAttributes(