diff --git a/app/components/PublicationDetail.vue b/app/components/PublicationDetail.vue index 7f79b34..d21e4db 100644 --- a/app/components/PublicationDetail.vue +++ b/app/components/PublicationDetail.vue @@ -6,6 +6,7 @@ import { useHistoryStore } from '~/stores/history' import { storeToRefs } from 'pinia' import { useSettingsStore } from '~/stores/settings' import type { SearchHit } from '~/types' +import { select } from '#build/ui' interface TypesenseHighlight { field?: string @@ -344,7 +345,7 @@ const currentMatchIdx = ref(0) function clearMatchMarks() { const container = paragraphsContainer.value if (!container) return - container.querySelectorAll('mark.search-match').forEach(m => { + container.querySelectorAll('mark.search-match').forEach((m) => { const parent = m.parentNode if (parent) { parent.replaceChild(document.createTextNode(m.textContent || ''), m) @@ -753,13 +754,43 @@ function highlightTextNodes(root: HTMLElement, terms: string[]): number { } return matches.length } +const isPopOverOpen = ref(false) +const anchor = ref({ x: 0, y: 0 }) +const virtualElement = computed(() => ({ + getBoundingClientRect: () => + ({ + width: 0, + height: 0, + left: anchor.value.x, + right: anchor.value.x, + top: anchor.value.y, + bottom: anchor.value.y, + ...anchor.value + } as DOMRect) +})) + +function handleSelection(event: MouseEvent) { + const selection = window.getSelection() + if (selection && selection.toString().length > 0) { + anchor.value = { x: event.clientX, y: event.clientY } + isPopOverOpen.value = true + } else { + isPopOverOpen.value = false + } +}