Skip to content

Build your personal knowledge base with Trilium Notes

feat(pdf): label a reference to an annotation as one

Elian Doran7de4c8ccd670
diff --git a/apps/client/src/services/link.spec.ts b/apps/client/src/services/link.spec.ts
index d3d5ecc4fe..f3ec9447d5 100644
--- a/apps/client/src/services/link.spec.ts
+++ b/apps/client/src/services/link.spec.ts
@@ -910,12 +910,14 @@ describe("getReferenceLinkTitle / getReferenceLinkTitleSync", () => {
expect(linkService.getReferenceLinkTitleSync(href)).toBe("Board: To Do");
});
- it("names the PDF a page reference points at, and the page after it", async () => {
+ it("names the PDF a reference points at, and the page or the annotation after it", async () => {
const pdf = buildNote({ title: "Paper" });
const href = `#root/${pdf.noteId}?page=5&annotation=12R`;
expect(await linkService.getReferenceLinkTitle(href)).toBe("Paper");
- expect(linkService.getReferenceLinkTitleSync(href)).toBe("Paper - pdf.page_reference");
+ expect(linkService.getReferenceLinkTitleSync(href)).toBe("Paper - pdf.annotation_reference");
+ expect(linkService.getReferenceLinkTitleSync(`#root/${pdf.noteId}?page=5`))
+ .toBe("Paper - pdf.page_reference");
});
it("getReferenceLinkTitleSync returns [missing note] when the note is not in cache", () => {
@@ -1006,14 +1008,18 @@ describe("loadReferenceLinkTitle", () => {
expect($column.hasClass("color-FF8800")).toBe(true);
});
- it("appends the page a PDF reference points at", async () => {
+ it("appends the page a PDF reference points at, or says it is an annotation on it", async () => {
const pdf = buildNote({ title: "Paper" });
- const $el = $("<span>");
+ const $page = $("<span>");
+ const $annotation = $("<span>");
- await linkService.loadReferenceLinkTitle($el, `#root/${pdf.noteId}?page=5&annotation=12R`);
+ await linkService.loadReferenceLinkTitle($page, `#root/${pdf.noteId}?page=5`);
+ await linkService.loadReferenceLinkTitle($annotation, `#root/${pdf.noteId}?page=5&annotation=12R`);
- expect($el.text()).toBe("Paperpdf.page_reference");
- expect($el.find("small span").hasClass("bx-file")).toBe(true);
+ expect($page.text()).toBe("Paperpdf.page_reference");
+ expect($page.find("small span").hasClass("bx-file")).toBe(true);
+ expect($annotation.text()).toBe("Paperpdf.annotation_reference");
+ expect($annotation.find("small span").hasClass("bx-comment-detail")).toBe(true);
});
it("falls back to a column glyph for a reference carrying no icon of its own", async () => {
diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts
index 518e2d0897..2f1546deb3 100644
--- a/apps/client/src/services/link.ts
+++ b/apps/client/src/services/link.ts
@@ -702,8 +702,8 @@ async function loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string | n
if (viewScope?.page) {
$el.append($("<small>").append(
- $("<span>").addClass("bx bx-file"),
- document.createTextNode(t("pdf.page_reference", { pageNumber: viewScope.page }))
+ $("<span>").addClass(viewScope.annotation ? "bx bx-comment-detail" : "bx bx-file"),
+ document.createTextNode(getPdfReferenceLabel(viewScope.page, viewScope.annotation))
));
}
@@ -777,12 +777,17 @@ function getReferenceLinkTitleSync(href: string) {
}
if (viewScope?.page) {
- return `${note.title} - ${t("pdf.page_reference", { pageNumber: viewScope.page })}`;
+ return `${note.title} - ${getPdfReferenceLabel(viewScope.page, viewScope.annotation)}`;
}
return note.title;
}
+/** What a reference to a PDF says after the title: the page, or the annotation on it. */
+function getPdfReferenceLabel(pageNumber: string, annotation: string | undefined) {
+ return t(annotation ? "pdf.annotation_reference" : "pdf.page_reference", { pageNumber });
+}
+
/* v8 ignore next -- the `print` device branch is evaluated once at module load; under test glob.device is undefined, so the false arm cannot be exercised */
if (glob.device !== "print") {
// TODO: Check why the event is not supported.
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index f27d9e4240..419df07666 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4016,7 +4016,8 @@
"annotation_note": "Note on page {{pageNumber}}",
"annotation_text_box": "Text box on page {{pageNumber}}",
"copy_reference": "Copy reference",
- "page_reference": "Page {{pageNumber}}"
+ "page_reference": "Page {{pageNumber}}",
+ "annotation_reference": "Annotation on page {{pageNumber}}"
},
"platform_indicator": {
"available_on": "Available on {{platform}}"
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/File/PDFs.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/File/PDFs.html
index b65818129e..7c042accb8 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/File/PDFs.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/File/PDFs.html
@@ -103,8 +103,9 @@ class="admonition tip">
</ul>
<p>Pasted into a text note, the reference becomes one of the&nbsp;<a class="reference-link"
href="#root/_help_hrZ1D00cLbal">Internal (reference) links</a>, showing
- the title of the PDF and the page. Clicking it opens the PDF and scrolls
- to the page or to the annotation.</p>
+ the title of the PDF followed by the page (<em>Page 5</em>), or by <em>Annotation on page 5</em> for
+ a reference to an annotation. Clicking it opens the PDF and scrolls to
+ the page or to the annotation.</p>
<p>A reference to an annotation also carries its page, so a link to an annotation
that was deleted still opens the right page.</p>
<aside class="admonition note">
diff --git a/docs/User Guide/User Guide/Note Types/File/PDFs.md b/docs/User Guide/User Guide/Note Types/File/PDFs.md
index 411ad24e38..ab6cf731d7 100644
--- a/docs/User Guide/User Guide/Note Types/File/PDFs.md
+++ b/docs/User Guide/User Guide/Note Types/File/PDFs.md
@@ -74,7 +74,7 @@ A link can open a PDF at a given page, or at one of its annotations. To create o
* To link to a page, right-click the page in the _Pages_ section of the <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/UI%20Elements/Right%20Sidebar.md">Right Sidebar</a> and select _Copy reference_.
* To link to an annotation, right-click it in the _Annotations_ section of the sidebar and select _Copy reference_.
-Pasted into a text note, the reference becomes one of the <a class="reference-link" href="../Text/Links/Internal%20(reference)%20links.md">Internal (reference) links</a>, showing the title of the PDF and the page. Clicking it opens the PDF and scrolls to the page or to the annotation.
+Pasted into a text note, the reference becomes one of the <a class="reference-link" href="../Text/Links/Internal%20(reference)%20links.md">Internal (reference) links</a>, showing the title of the PDF followed by the page (_Page 5_), or by _Annotation on page 5_ for a reference to an annotation. Clicking it opens the PDF and scrolls to the page or to the annotation.
A reference to an annotation also carries its page, so a link to an annotation that was deleted still opens the right page.