Skip to content

Build your personal knowledge base with Trilium Notes

fix(pdf): stop tinting an unsaved text box's sidebar row with its font colour

Elian Doran3a9d8c6a1301
diff --git a/packages/pdfjs-viewer/src/annotations.spec.ts b/packages/pdfjs-viewer/src/annotations.spec.ts
index 1813dfff34..54264e9fdc 100644
--- a/packages/pdfjs-viewer/src/annotations.spec.ts
+++ b/packages/pdfjs-viewer/src/annotations.spec.ts
@@ -254,7 +254,9 @@ describe("extraction from a real document", () => {
const { annotations } = viewer.lastMessageOfType("pdfjs-viewer-annotations");
expect(annotations.filter((annotation: any) => annotation.id.startsWith("pdfjs_internal_editor"))).toEqual([
expect.objectContaining({ id: "pdfjs_internal_editor_0", type: "highlight", pageNumber: 3, color: "#ffff98" }),
- expect.objectContaining({ id: "pdfjs_internal_editor_1", type: "freetext", contents: "typed words", pageNumber: 1 })
+ // pdf.js serializes a text box's *font* colour under `color`; the sidebar tints a row with
+ // this field, and a black tint behind a note is not what anyone drew.
+ expect.objectContaining({ id: "pdfjs_internal_editor_1", type: "freetext", contents: "typed words", pageNumber: 1, color: null })
]);
// The document's own annotations are still there, and the edited one is not duplicated.
expect(annotations.filter((annotation: any) => annotation.id === "5R")).toHaveLength(1);
diff --git a/packages/pdfjs-viewer/src/annotations.ts b/packages/pdfjs-viewer/src/annotations.ts
index 6f157a175b..748dcd3818 100644
--- a/packages/pdfjs-viewer/src/annotations.ts
+++ b/packages/pdfjs-viewer/src/annotations.ts
@@ -202,7 +202,8 @@ function unsavedAnnotations(storage: any): PdfAnnotationInfo[] {
highlightedText: "",
author: "",
pageNumber: (serialized.pageIndex ?? 0) + 1,
- color: serialized.color ? rgbToHex(serialized.color) : null,
+ // As in applyEditorOverrides: a text box's colour is that of its text, not a tint.
+ color: serialized.color && type !== "freetext" ? rgbToHex(serialized.color) : null,
creationDate: null,
modificationDate: null
});