:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(conversations): hyperlink selection when pasting long URLs (#69189)
Xander1cdb2598053f
diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex c28015eb08e8..7be7682c71ad 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -2801,6 +2801,9 @@ importers:'@tiptap/extensions':specifier: '*'+ '@tiptap/pm':+ specifier: '*'+ version: 3.20.1'@tiptap/react':specifier: '*'version: 3.20.1(@floating-ui/[email protected])(@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected])(@types/[email protected](@types/[email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])diff --git a/products/conversations/frontend/components/Editor/SupportEditor.tsx b/products/conversations/frontend/components/Editor/SupportEditor.tsxindex f935cee7d558..8ba2712a7097 100644--- a/products/conversations/frontend/components/Editor/SupportEditor.tsx+++ b/products/conversations/frontend/components/Editor/SupportEditor.tsx@@ -7,6 +7,7 @@ import { Image } from '@tiptap/extension-image'import { Link } from '@tiptap/extension-link'import { Underline } from '@tiptap/extension-underline'import { Placeholder } from '@tiptap/extensions'+import { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state'import {EditorContent,Extension,@@ -169,6 +170,54 @@ const LinkExtension = Link.configure({},})+/** True when the whole string is a single http(s) URL with no whitespace. */+function isSingleHttpUrl(text: string): boolean {+ if (!text || /\s/.test(text)) {+ return false+ }+ try {+ const { protocol } = new URL(text)+ return protocol === 'http:' || protocol === 'https:'+ } catch {+ return false+ }+}++// TipTap's built-in linkOnPaste only wraps the selection when linkify matches the+// clipboard text exactly, which it fails to do for some long URLs, leaving the+// selection overwritten with plain text instead of hyperlinked. Handle the+// "URL pasted over a selection" case ourselves so URL length doesn't matter.+const LinkOnPasteExtension = Extension.create({+ name: 'supportLinkOnPaste',+ priority: 150, // Run before the Link extension's own paste handler+ addProseMirrorPlugins() {+ const linkType = this.editor.schema.marks.link+ return [+ new Plugin({+ key: new PluginKey('supportLinkOnPaste'),+ props: {+ handlePaste: (view, event) => {+ const { selection } = view.state+ // Only wrap a non-empty text selection. Node selections (e.g. an image)+ // can't hold inline marks, so let those pastes fall through untouched.+ if (!(selection instanceof TextSelection) || selection.empty || !linkType) {+ return false+ }+ const text = event.clipboardData?.getData('text/plain').trim()+ if (!text || !isSingleHttpUrl(text)) {+ return false+ }+ view.dispatch(+ view.state.tr.addMark(selection.from, selection.to, linkType.create({ href: text }))+ )+ return true+ },+ },+ }),+ ]+ },+})+export const SUPPORT_EXTENSIONS = [MentionsExtension,RichContentNodeMention,@@ -195,6 +244,7 @@ export const SUPPORT_EXTENSIONS = [Underline, // Cmd+UImageExtension,LinkExtension,+ LinkOnPasteExtension,SupportCodeBlockExtension,]diff --git a/products/conversations/package.json b/products/conversations/package.jsonindex 29d3fd627fc8..a716ceb9bdf4 100644--- a/products/conversations/package.json+++ b/products/conversations/package.json@@ -31,6 +31,7 @@"@tiptap/extension-link": "*","@tiptap/extension-underline": "*","@tiptap/extensions": "*",+ "@tiptap/pm": "*","@tiptap/react": "*","@tiptap/starter-kit": "*","@types/react": "*",