Fixed copy functionality

This commit is contained in:
Julio Ruiz 2026-05-25 21:12:42 -05:00
parent 09b99985eb
commit 995111612c
2 changed files with 50 additions and 19 deletions

View File

@ -858,6 +858,7 @@ function highlightTextNodes(root: HTMLElement, terms: string[]): number {
/>
<template #content>
<UFieldGroup size="sm" orientation="horizontal" class="bg-white p-0 rounded-md shadow-md">
<UPopover>
<UButton
v-if="hit.document.text"
icon="ph-note-pencil"
@ -866,6 +867,13 @@ function highlightTextNodes(root: HTMLElement, terms: string[]): number {
size="lg"
@click="addNote(hit.document.id)"
></UButton>
<template #content>
<UEditor />
</template>
</UPopover>
<UPopover>
<UButton
v-if="hit.document.text"
icon="ph-highlighter"
@ -874,6 +882,11 @@ function highlightTextNodes(root: HTMLElement, terms: string[]): number {
size="lg"
@click="highlightParagraph(hit.document.id)"
></UButton>
<template #content>
<UColorPicker />
</template>
</UPopover>
<UButton
v-if="hit.document.text"
icon="ph-copy"

View File

@ -1,12 +1,30 @@
/* Copy to Clipboard */
export async function copyToClipboard(textToCopy: string, type: string, id: string) {
export async function copyToClipboard() {
const toast = useToast()
const selection = window.getSelection()
const container = document.createElement('div')
const range = selection?.getRangeAt(0)
container.appendChild(range.cloneContents())
const htmlOutput = container.innerHTML
const textOutput = selection?.toString()
try {
await navigator.clipboard.writeText(textToCopy)
// Modern Clipboard API requires ClipboardItem
const clipboardItem = new ClipboardItem({
'text/html': new Blob([htmlOutput], { type: 'text/html' }),
'text/plain': new Blob([textOutput], { type: 'text/plain' })
})
await navigator.clipboard.write([clipboardItem])
window.getSelection()?.removeAllRanges()
toast.add({
title: 'Texto copiado!',
description: `${textToCopy}`,
description: `${textOutput}`,
icon: 'ph-clipboard-text',
color: type == 'activities' ? 'success' : 'info'
})