Skip to content

Fix copy (Cmd+C) broken in Safari on plan viewer#785

Merged
backnotprop merged 11 commits into
mainfrom
fix/safari-cp
May 24, 2026
Merged

Fix copy (Cmd+C) broken in Safari on plan viewer#785
backnotprop merged 11 commits into
mainfrom
fix/safari-cp

Conversation

@backnotprop
Copy link
Copy Markdown
Owner

Summary

  • Viewer.tsx: Replaced the keydown Cmd+C handler with a native copy event listener using synchronous clipboardData.setData(). Safari rejects the async navigator.clipboard.writeText() API when the user-gesture chain is broken by await, and web-highlighter clears the DOM selection on mouseup so native copy has nothing to grab — this fixes both issues.
  • AnnotationToolbar.tsx: Added document.execCommand('copy') fallback around the toolbar's copy button for extra safety in restrictive environments.

Test plan

  • Open a plan in Safari, select text, press Cmd+C — verify the selected text is copied
  • Verify copy still works in Chrome and Firefox
  • Verify the annotation toolbar copy button works in Safari
  • Verify copy inside input/textarea fields is not intercepted

Safari rejects async navigator.clipboard.writeText() outside the
immediate user-gesture window.  The old keydown handler broke the
gesture chain with an await, and web-highlighter already clears
the DOM selection on mouseup so native copy had nothing to grab.

Switch Viewer to the synchronous copy event + clipboardData.setData()
which works across all browsers.  Add an execCommand fallback to the
AnnotationToolbar copy button for extra safety.
Cmd+C now works reliably via the native copy event, so the toolbar
copy button is redundant. Code block and table copy buttons are kept.
Touch users have no Cmd+C fallback since web-highlighter clears the
native selection. Detect (pointer: coarse) and conditionally render
the copy button + execCommand fallback for iPad/phone users.
Prevents the copy handler from hijacking Cmd+C when the target is
outside the viewer (sidebar, annotations panel, code popout, etc.).
The iframe copy event can't reach the parent document handler, so the
toolbar button is the only copy path for HTML annotation mode.
Separates "what text to copy" from "whether to show the button."
Only Viewer's text selection toolbar hides it (desktop only, has
keyboard handler). HtmlViewer and code block toolbars always show it.
@backnotprop backnotprop merged commit 05392eb into main May 24, 2026
10 checks passed
@backnotprop backnotprop deleted the fix/safari-cp branch May 24, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant