Skip to content

Commit 769ca85

Browse files
committed
feat(rich-editor): copy-link button shows a checkmark on copy
Use the shared useCopyToClipboard hook so the link hover card's Copy button swaps to a Check for ~2s after copying, matching the rest of the platform.
1 parent 298021c commit 769ca85

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/menus

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/menus/link-hover-card.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getMarkRange } from '@tiptap/core'
44
import type { Editor } from '@tiptap/react'
55
import { Check, Copy, Pencil, Unlink } from 'lucide-react'
66
import { createPortal } from 'react-dom'
7+
import { useCopyToClipboard } from '@/hooks/use-copy-to-clipboard'
78
import { normalizeLinkHref } from '../markdown-fidelity'
89
import { applyLink, LinkUrlInput } from './link-editing'
910
import { ToolbarButton } from './toolbar-button'
@@ -46,6 +47,7 @@ export function LinkHoverCard({ editor }: LinkHoverCardProps) {
4647
const isEditing = draftHref !== null
4748
const editInputRef = useRef<HTMLInputElement>(null)
4849
const floatingRef = useRef<HTMLDivElement>(null)
50+
const { copied, copy } = useCopyToClipboard()
4951
const hideTimerRef = useRef<number | undefined>(undefined)
5052

5153
// Keep the card anchored to the hovered link with Floating UI's DOM core (the same primitive the
@@ -175,7 +177,13 @@ export function LinkHoverCard({ editor }: LinkHoverCardProps) {
175177
{rawHref}
176178
</span>
177179
)}
178-
<ToolbarButton icon={Copy} label='Copy link' onClick={() => copyToClipboard(rawHref)} />
180+
<ToolbarButton
181+
icon={copied ? Check : Copy}
182+
label={copied ? 'Copied' : 'Copy link'}
183+
onClick={() => {
184+
void copy(rawHref)
185+
}}
186+
/>
179187
{canEdit && <ToolbarButton icon={Pencil} label='Edit link' onClick={startEdit} />}
180188
{canEdit && <ToolbarButton icon={Unlink} label='Remove link' onClick={removeLink} />}
181189
</>
@@ -184,7 +192,3 @@ export function LinkHoverCard({ editor }: LinkHoverCardProps) {
184192
document.body
185193
)
186194
}
187-
188-
function copyToClipboard(text: string) {
189-
if (text) void navigator.clipboard?.writeText(text).catch(() => {})
190-
}

0 commit comments

Comments
 (0)