Skip to content

Build your personal knowledge base with Trilium Notes

fix(pdf): let an untinted annotation row read in the theme's colours

Elian Doran8633d9f0b48d
diff --git a/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.css b/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.css
index 415f83ae85..b108074ef6 100644
--- a/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.css
+++ b/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.css
@@ -2,7 +2,6 @@
width: 100%;
}
-
.pdf-annotation-item {
display: flex;
align-items: flex-start;
@@ -12,30 +11,32 @@
border-radius: 6px;
cursor: pointer;
transition: filter 0.2s;
+ /* An untinted row sits on the panel itself, so it reads in the theme's colours. */
+ --annotation-text-color: var(--main-text-color);
+ --annotation-muted-text-color: var(--muted-text-color);
+ color: var(--annotation-text-color);
}
-.pdf-annotation-item:hover {
- filter: brightness(0.9);
+/* A tinted row carries its annotation's own colour behind the text, which no theme knows about,
+ so the text is fixed to suit the tint: dark on a pale highlight, light on the pen's black. */
+.pdf-annotation-item.tinted {
+ --annotation-text-color: #333;
+ --annotation-muted-text-color: #555;
}
-.pdf-annotation-item,
-.pdf-annotation-item .tn-icon {
- color: #333;
+.pdf-annotation-item.tinted-dark {
+ --annotation-text-color: #f0f0f0;
+ --annotation-muted-text-color: #d0d0d0;
+}
+
+.pdf-annotation-item:hover {
+ filter: brightness(0.9);
}
.pdf-annotation-item .tn-icon {
flex-shrink: 0;
font-size: 18px;
-}
-
-/* Rows tinted with a dark annotation colour (the pen defaults to black) invert their text. */
-.pdf-annotation-item.on-dark,
-.pdf-annotation-item.on-dark .tn-icon,
-.pdf-annotation-item.on-dark .pdf-annotation-untitled,
-.pdf-annotation-item.on-dark .pdf-annotation-highlighted-text,
-.pdf-annotation-item.on-dark .pdf-annotation-contents,
-.pdf-annotation-item.on-dark .pdf-annotation-author {
- color: #f0f0f0;
+ color: var(--annotation-text-color);
}
.pdf-annotation-info {
@@ -45,13 +46,13 @@
.pdf-annotation-untitled {
font-size: 13px;
- color: #555;
+ color: var(--annotation-muted-text-color);
}
.pdf-annotation-highlighted-text {
font-size: 13px;
font-style: italic;
- color: #555;
+ color: var(--annotation-muted-text-color);
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
@@ -60,7 +61,7 @@
.pdf-annotation-contents {
font-size: 13px;
- color: #333;
+ color: var(--annotation-text-color);
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 3;
@@ -69,6 +70,6 @@
.pdf-annotation-author {
font-size: 11px;
- color: #555;
+ color: var(--annotation-muted-text-color);
margin-top: 2px;
}
diff --git a/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.spec.tsx b/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.spec.tsx
index 4f1947c05f..191d57bb28 100644
--- a/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.spec.tsx
+++ b/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.spec.tsx
@@ -102,17 +102,24 @@ describe("PdfAnnotations", () => {
expect(rows[1].querySelector(".tn-icon")?.className).toContain("bxs-comment-detail");
});
- it("flips the row's text to light on a dark annotation colour", () => {
- // The pen draws in black by default, and the row is tinted with the annotation's own
- // colour — the default dark text would be unreadable on it.
+ it("colours a row's text for the tint behind it, and leaves an untinted row to the theme", () => {
+ // A row is tinted with its annotation's own colour, so its text cannot follow the theme:
+ // dark text for a pale highlight, light for the pen's default black. A text box has no
+ // colour, so its row sits on the panel itself and takes the theme's text colour — the
+ // fixed dark text would vanish on a dark theme's panel.
const container = renderPanel([
+ annotation({ id: "5R", color: "#ffff98" }),
annotation({ id: "18R", type: "ink", color: "#000000" }),
- annotation({ id: "5R", color: "#ffff98" })
+ annotation({ id: "19R", type: "freetext", color: null })
]);
- const rows = [ ...container.querySelectorAll(".pdf-annotation-item") ];
- expect(rows[0].classList.contains("on-dark")).toBe(true);
- expect(rows[1].classList.contains("on-dark")).toBe(false);
+ const classes = [ ...container.querySelectorAll(".pdf-annotation-item") ]
+ .map((row) => [ ...row.classList ].filter((cls) => cls !== "pdf-annotation-item"));
+ expect(classes).toEqual([
+ [ "tinted" ],
+ [ "tinted", "tinted-dark" ],
+ []
+ ]);
});
});
diff --git a/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.tsx b/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.tsx
index 6b8cd8762d..5b2315045c 100644
--- a/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.tsx
+++ b/apps/client/src/widgets/sidebar/pdf/PdfAnnotations.tsx
@@ -61,7 +61,11 @@ function PdfAnnotationItem({
return (
<div
- className={clsx("pdf-annotation-item", isDark(annotation.color) && "on-dark")}
+ className={clsx(
+ "pdf-annotation-item",
+ annotation.color && "tinted",
+ isDark(annotation.color) && "tinted-dark"
+ )}
onClick={() => onNavigate(annotation.id, annotation.pageNumber)}
style={annotation.color ? { backgroundColor: annotation.color } : undefined}
>
@@ -86,7 +90,8 @@ function PdfAnnotationItem({
/**
* Whether a row tinted with this annotation colour needs light text. Highlights are pastel, but
- * the pen draws in black by default, and the row's dark default text would vanish on it.
+ * the pen draws in black by default, and the dark text a tinted row otherwise gets would vanish
+ * on it.
*/
export function isDark(color: string | null) {
const rgb = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color ?? "");