diff --git a/src/lib/components/chat/FileNav/CommentFilePreview.svelte b/src/lib/components/chat/FileNav/CommentFilePreview.svelte index 4d114e335f..31b6f17915 100644 --- a/src/lib/components/chat/FileNav/CommentFilePreview.svelte +++ b/src/lib/components/chat/FileNav/CommentFilePreview.svelte @@ -39,6 +39,7 @@ let hoveredId: string | null = null; let pinned = false; let touchInteraction = false; + let overHighlight = false; let popoverX = 0; let popoverY = 0; let closeTimer: ReturnType; @@ -99,10 +100,38 @@ if (!pinned) closeTimer = setTimeout(() => (hoveredId = null), 100); }; const reveal = (event: MouseEvent | FocusEvent, pin = false) => { - const element = (event.target as HTMLElement).closest( + overHighlight = false; + if (event instanceof MouseEvent && (event.buttons || window.getSelection()?.type === 'Range')) { + if (!pinned) { + keepOpen(); + hoveredId = null; + } + return; + } + let element = (event.target as HTMLElement).closest( '[data-file-comment-id],[data-cell]' ); - if (!element) return; + // Highlights are pointer-transparent so dragging selects the document text. + if (!element && event instanceof MouseEvent) { + const page = (event.target as HTMLElement).closest('.pdf-page-wrapper'); + element = + Array.from((page ?? root).querySelectorAll('[data-comment-highlight]')).find( + (highlight) => { + const rect = highlight.getBoundingClientRect(); + return ( + event.clientX >= rect.left && + event.clientX <= rect.right && + event.clientY >= rect.top && + event.clientY <= rect.bottom + ); + } + ) ?? null; + } + if (!element) { + closeLater(); + return; + } + overHighlight = event instanceof MouseEvent && !!element.dataset.commentHighlight; const id = element.dataset.fileCommentId ?? comments.find( @@ -236,12 +265,20 @@
(touchInteraction = e.pointerType === 'touch')} + on:pointerdown={(e) => { + touchInteraction = e.pointerType === 'touch'; + if (!(e.target as HTMLElement).closest('[data-file-comment-id],[data-cell]')) { + keepOpen(); + pinned = false; + hoveredId = null; + } + }} on:click={(e) => reveal(e, touchInteraction || e.detail === 0)} > {#if loading}
@@ -347,6 +384,10 @@ {/if}