Skip to content

Commit

Permalink
fix bug with textContents and check links for duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzokuken committed Dec 16, 2024
1 parent 50ad6b1 commit 7849bc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/editor/tools.js").AnnotationEditorUIManager} AnnotationEditorUIManager */

import { AnnotationLayer } from "pdfjs-lib";
import { AnnotationLayer, Util } from "pdfjs-lib";
import { PresentationModeState } from "./ui_utils.js";

/**
Expand Down Expand Up @@ -119,12 +119,19 @@ class AnnotationLayerBuilder {
return;
}

if (annotations.length === 0) {
// Because we could end up creating duplicate annotations, avoid injecting
// any if there are already annotations in the layer. In the future, this
// should be something smarter so we could avoid overlaps.
annotations.push(...linkAnnotations);
}
const uniqueLinks = linkAnnotations.filter(link => {
for (const annotation of annotations) {
if (
annotation.subtype === "Link" &&
annotation.url === link.url &&
Util.intersect(annotation.rect, link.rect) !== null
) {
return false;
}
}
return true;
});
annotations.push(...uniqueLinks);

// Create an annotation layer div and render the annotations
// if there is at least one annotation.
Expand Down
2 changes: 1 addition & 1 deletion web/autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Autolinker {

static processLinks(pdfPageView) {
const [text, diffs] = normalize(
pdfPageView._textHighlighter.textContentItemsStr.join("")
pdfPageView._textHighlighter.textContentItemsStr.join("\n")
);
const matches = text.matchAll(Autolinker.#urlRegex);
const links = [];
Expand Down

0 comments on commit 7849bc0

Please sign in to comment.