Fix copy (Cmd+C) broken in Safari on plan viewer#785
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
keydownCmd+C handler with a nativecopyevent listener using synchronousclipboardData.setData(). Safari rejects the asyncnavigator.clipboard.writeText()API when the user-gesture chain is broken byawait, and web-highlighter clears the DOM selection onmouseupso native copy has nothing to grab — this fixes both issues.document.execCommand('copy')fallback around the toolbar's copy button for extra safety in restrictive environments.Test plan