(text: string)
| 38 | } |
| 39 | |
| 40 | export async function copyTextToClipboard(text: string): Promise<boolean> { |
| 41 | const useSelectionFirst = shouldCopyWithSelectionFirst(); |
| 42 | if (useSelectionFirst && copyWithSelection(text)) { |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | const clipboard = typeof navigator !== "undefined" ? navigator.clipboard : undefined; |
| 47 | if (clipboard?.writeText) { |
| 48 | try { |
| 49 | await clipboard.writeText(text); |
| 50 | return true; |
| 51 | } catch { |
| 52 | // Fall back below when the browser still allows synchronous copy. |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return !useSelectionFirst && copyWithSelection(text); |
| 57 | } |
no test coverage detected