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, Document,
LinkDecorator, LinkDecorator,
// TagDecorator,
Tags.configure({ Tags.configure({
HTMLAttributes: { HTMLAttributes: {
class: 'inline-tag', 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 const hashRegex = /#/g
let hashMatch let hashMatch
while ((hashMatch = hashRegex.exec(text))) { while ((hashMatch = hashRegex.exec(text))) {
@@ -38,7 +42,7 @@ export function insertTagAt(text: string, position: number, tag: string) {
const target = getHashtagAt(text, position) const target = getHashtagAt(text, position)
if (target) { if (target) {
return `${text.slice(0, target.index)}#${tag} ${text.slice( 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 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 {mergeAttributes, Node} from '@tiptap/core'
import {Node as ProseMirrorNode} from '@tiptap/pm/model' import {Node as ProseMirrorNode} from '@tiptap/pm/model'
@@ -127,14 +131,6 @@ export const Tags = Node.create<TagOptions>({
}, },
renderHTML({node, HTMLAttributes}) { renderHTML({node, HTMLAttributes}) {
console.log(
'renderText',
node,
this.options.renderLabel({
options: this.options,
node,
}),
)
return [ return [
'span', 'span',
mergeAttributes( mergeAttributes(