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,22 +858,35 @@ function highlightTextNodes(root: HTMLElement, terms: string[]): number {
/> />
<template #content> <template #content>
<UFieldGroup size="sm" orientation="horizontal" class="bg-white p-0 rounded-md shadow-md"> <UFieldGroup size="sm" orientation="horizontal" class="bg-white p-0 rounded-md shadow-md">
<UButton <UPopover>
v-if="hit.document.text" <UButton
icon="ph-note-pencil" v-if="hit.document.text"
variant="ghost" icon="ph-note-pencil"
color="neutral" variant="ghost"
size="lg" color="neutral"
@click="addNote(hit.document.id)" size="lg"
></UButton> @click="addNote(hit.document.id)"
<UButton ></UButton>
v-if="hit.document.text"
icon="ph-highlighter" <template #content>
variant="ghost" <UEditor />
color="neutral" </template>
size="lg" </UPopover>
@click="highlightParagraph(hit.document.id)"
></UButton> <UPopover>
<UButton
v-if="hit.document.text"
icon="ph-highlighter"
variant="ghost"
color="neutral"
size="lg"
@click="highlightParagraph(hit.document.id)"
></UButton>
<template #content>
<UColorPicker />
</template>
</UPopover>
<UButton <UButton
v-if="hit.document.text" v-if="hit.document.text"
icon="ph-copy" icon="ph-copy"

View File

@ -1,12 +1,30 @@
/* Copy to Clipboard */ /* Copy to Clipboard */
export async function copyToClipboard(textToCopy: string, type: string, id: string) { export async function copyToClipboard() {
const toast = useToast() 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 { 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({ toast.add({
title: 'Texto copiado!', title: 'Texto copiado!',
description: `${textToCopy}`, description: `${textOutput}`,
icon: 'ph-clipboard-text', icon: 'ph-clipboard-text',
color: type == 'activities' ? 'success' : 'info' color: type == 'activities' ? 'success' : 'info'
}) })