Skip to content

Commit

Permalink
Enable selecting the text underneath annotations
Browse files Browse the repository at this point in the history
Fixes #778
  • Loading branch information
allanlasser committed Nov 27, 2024
1 parent ac7226a commit 9fe8139
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/components/viewer/AnnotationLayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Assumes it's a child of a ViewerContext
opacity: 0.5;
pointer-events: all;
mix-blend-mode: multiply;
/* pointer-events: none; */
pointer-events: none;
}
a.note-highlight.public {
Expand Down
29 changes: 29 additions & 0 deletions src/lib/components/viewer/PDFPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Selectable text can be rendered in one of two ways:
- Passed in as a server-fetched JSON object
-->
<script lang="ts">
import { onMount } from "svelte";
import type { TextPosition } from "$lib/api/types";
import { page as pageStore } from "$app/stores";
Expand Down Expand Up @@ -174,6 +175,34 @@ Selectable text can be rendered in one of two ways:
});
}
function checkForHighlightClick(click: MouseEvent) {
const clickX = click.clientX;
const clickY = click.clientY;
const highlights: NodeListOf<HTMLElement> =
container.querySelectorAll(".note-highlight");
highlights.forEach((highlight) => {
const { top, left, right, bottom } = highlight.getBoundingClientRect();
const isSelectionClick = window.getSelection()?.type === "Range";
const isNoteClick =
clickX >= left &&
clickX <= right &&
clickY >= top &&
clickY <= bottom &&
!isSelectionClick;
if (isNoteClick) {
highlight.click();
}
});
}
onMount(() => {
container.addEventListener("click", checkForHighlightClick);
return () => {
container.removeEventListener("click", checkForHighlightClick);
};
});
function onResize() {
numericScale = fitPage(width, height, container, scale);
}
Expand Down

0 comments on commit 9fe8139

Please sign in to comment.