Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: simplify clipboard fallback logic by removing support check
  • Loading branch information
Myestery committed Aug 19, 2025
commit 3f0b9e6e167a442b4c978201b59ddf994ca766e0
24 changes: 10 additions & 14 deletions src/composables/useCopyToClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useToast } from 'primevue/usetoast'
import { t } from '@/i18n'

export function useCopyToClipboard() {
const { copy, copied, isSupported } = useClipboard()
const { copy, copied } = useClipboard()
const toast = useToast()
const showSuccessToast = () => {
toast.add({
Expand All @@ -24,6 +24,7 @@ export function useCopyToClipboard() {

function fallbackCopy(text: string) {
const textarea = document.createElement('textarea')
textarea.setAttribute('readonly', '')
textarea.value = text
textarea.style.position = 'fixed'
textarea.style.opacity = '0'
Expand All @@ -46,21 +47,16 @@ export function useCopyToClipboard() {
}

const copyToClipboard = async (text: string) => {
if (isSupported) {
try {
await copy(text)
if (copied.value) {
showSuccessToast()
} else {
// If VueUse copy failed, try fallback
fallbackCopy(text)
}
} catch (err) {
// VueUse copy failed, try fallback
try {
await copy(text)
if (copied.value) {
showSuccessToast()
} else {
// If VueUse copy failed, try fallback
fallbackCopy(text)
}
} else {
// Clipboard API not supported, use fallback
} catch (err) {
// VueUse copy failed, try fallback
fallbackCopy(text)
}
}
Expand Down
Loading