···3737import {type TextInputProps} from './TextInput.types'
3838import {type AutocompleteRef, createSuggestion} from './web/Autocomplete'
3939import {type Emoji} from './web/EmojiPicker'
4040-import {LinkDecorator} from './web/LinkDecorator'
4141-import {TagDecorator} from './web/TagDecorator'
4040+import {Decorator} from './web/Decorator'
42414342export function TextInput({
4443 ref,
···6463 const extensions = useMemo(
6564 () => [
6665 Document,
6767- LinkDecorator,
6868- TagDecorator,
6666+ Decorator,
6967 Mention.configure({
7068 HTMLAttributes: {
7169 class: 'mention',
+68
src/view/com/composer/text-input/web/Decorator.ts
···11+/**
22+ * TipTap is a stateful rich-text editor, which is extremely useful
33+ * when you _want_ it to be stateful formatting such as bold and italics.
44+ *
55+ * However we also use "stateless" behaviors, specifically for URLs
66+ * where the text itself drives the formatting.
77+ *
88+ * This plugin uses a regex to detect URIs and then applies
99+ * link decorations (a <span> with the "autolink") class. That avoids
1010+ * adding any stateful formatting to TipTap's document model.
1111+ *
1212+ * We then run the URI detection again when constructing the
1313+ * RichText object from TipTap's output and merge their features into
1414+ * the facet-set.
1515+ */
1616+1717+import {Mark} from '@tiptap/core'
1818+import {type Node as ProsemirrorNode} from '@tiptap/pm/model'
1919+import {Plugin, PluginKey} from '@tiptap/pm/state'
2020+import {Decoration, DecorationSet} from '@tiptap/pm/view'
2121+import {markup_main} from '#/lib/twelve/markup.js'
2222+2323+function getDecorations(doc: ProsemirrorNode) {
2424+ const decorations: Decoration[] = []
2525+2626+ let text = doc.textContent
2727+ for (let span of markup_main(text)) {
2828+ decorations.push(
2929+ Decoration.inline(span.start, span.end+1, {
3030+ class: 'autolink',
3131+ }),
3232+ )
3333+ }
3434+3535+ return DecorationSet.create(doc, decorations)
3636+}
3737+3838+const tagDecoratorPlugin: Plugin = new Plugin({
3939+ key: new PluginKey('link-decorator'),
4040+4141+ state: {
4242+ init: (_, {doc}) => getDecorations(doc),
4343+ apply: (transaction, decorationSet) => {
4444+ if (transaction.docChanged) {
4545+ return getDecorations(transaction.doc)
4646+ }
4747+ return decorationSet.map(transaction.mapping, transaction.doc)
4848+ },
4949+ },
5050+5151+ props: {
5252+ decorations(state) {
5353+ return tagDecoratorPlugin.getState(state)
5454+ },
5555+ },
5656+})
5757+5858+export const Decorator = Mark.create({
5959+ name: 'markup-decorator',
6060+ priority: 1000,
6161+ keepOnSplit: false,
6262+ inclusive() {
6363+ return true
6464+ },
6565+ addProseMirrorPlugins() {
6666+ return [tagDecoratorPlugin]
6767+ },
6868+})