Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable selecting the text underneath annotations #906

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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