Skip to content

Build your personal knowledge base with Trilium Notes

refactor(office): scroll preview on an unpadded host, not the padded body

Elian Doranbcc0fb577519
diff --git a/apps/client/src/services/content_renderer.css b/apps/client/src/services/content_renderer.css
index d9c42515b0..bdde3cfa0f 100644
--- a/apps/client/src/services/content_renderer.css
+++ b/apps/client/src/services/content_renderer.css
@@ -45,12 +45,19 @@
}
/* Office document preview — shared by this rendered-content path and the file type
- widget (Office.tsx); this stylesheet is part of the startup bundle. */
+ widget (Office.tsx); this stylesheet is part of the startup bundle.
+ Mirroring the read-only text structure, the body is plain padded content while
+ scrolling happens on an unpadded ancestor (.office-preview-scroll here,
+ .note-detail-file in the type widget) — a scroller's own bottom padding is not
+ reliably part of the scrollable area across browsers. */
.office-preview-body {
- overflow: auto;
padding: 15px;
}
+.office-preview-scroll {
+ overflow: auto;
+}
+
.office-preview-loading {
display: flex;
align-items: center;
@@ -64,7 +71,7 @@
flex-direction: column;
height: 100%;
- .office-preview-body {
+ .office-preview-scroll {
flex-grow: 1;
}
}
diff --git a/apps/client/src/services/content_renderer.spec.ts b/apps/client/src/services/content_renderer.spec.ts
index 0e8cdfdb56..7750ba7be7 100644
--- a/apps/client/src/services/content_renderer.spec.ts
+++ b/apps/client/src/services/content_renderer.spec.ts
@@ -395,7 +395,8 @@ describe("getRenderedContent office rendering", () => {
const { type, $renderedContent } = await getRenderedContent(note);
expect(type).toBe("office");
expect(renderOfficeToHtml).toHaveBeenCalledWith("notes", note.noteId);
- expect($renderedContent.find(".office-preview-body").html()).toContain("converted");
+ // the padded body sits inside a dedicated, unpadded scroll host
+ expect($renderedContent.find(".office-preview-scroll > .office-preview-body").html()).toContain("converted");
// the file remains downloadable / openable
expect($renderedContent.find(".file-download").length).toBe(1);
expect($renderedContent.find(".file-open").length).toBe(1);
@@ -408,7 +409,7 @@ describe("getRenderedContent office rendering", () => {
const { type, $renderedContent } = await getRenderedContent(note);
expect(type).toBe("office");
expect($renderedContent.find(".admonition.caution").length).toBe(1);
- expect($renderedContent.find(".office-preview-body").length).toBe(0);
+ expect($renderedContent.find(".office-preview-scroll, .office-preview-body").length).toBe(0);
});
it("does not run the heavy conversion in tooltip mode", async () => {
diff --git a/apps/client/src/services/content_renderer.ts b/apps/client/src/services/content_renderer.ts
index 2a67236ab0..7be1f8461e 100644
--- a/apps/client/src/services/content_renderer.ts
+++ b/apps/client/src/services/content_renderer.ts
@@ -353,17 +353,21 @@ async function renderFile(entity: FNote | FAttachment, type: string, $renderedCo
async function renderOffice(entity: FNote | FAttachment, $renderedContent: JQuery<HTMLElement>) {
const { entityType, entityId } = getEntityTypeAndId(entity);
+ // The scroll host is a separate, unpadded element (like the note view's .scrolling-container)
+ // so the body's padding scrolls with the document instead of sitting on the scroller itself.
const $content = $('<div class="office-preview">');
+ const $scroll = $('<div class="office-preview-scroll">');
const $body = $('<div class="ck-content office-preview-body">');
$body.append($('<div class="office-preview-loading">').append($('<span class="bx bx-loader bx-spin">')).append(document.createTextNode(t("content_renderer.office_rendering"))));
- $content.append($body);
+ $scroll.append($body);
+ $content.append($scroll);
$renderedContent.append($content);
try {
$body.html(await renderOfficeToHtml(entityType, entityId));
} catch (e) {
console.warn("Failed to render office document preview:", getErrorMessage(e));
- $body.remove();
+ $scroll.remove();
$content.prepend($("<div>").addClass("admonition caution").text(t("content_renderer.office_render_error")));
}
diff --git a/apps/client/src/widgets/type_widgets/File.css b/apps/client/src/widgets/type_widgets/File.css
index 85e1e446c3..529cac6272 100644
--- a/apps/client/src/widgets/type_widgets/File.css
+++ b/apps/client/src/widgets/type_widgets/File.css
@@ -11,11 +11,6 @@
padding: 0;
}
-.note-detail.full-height .note-detail-file[data-preview-type="pdf"],
-.note-detail.full-height .note-detail-file[data-preview-type="video"] {
- overflow: hidden;
-}
-
/* Rendered by CodeBlock, so the same <pre> also carries .code-block; the element selector keeps
these layout rules winning that equal-specificity fight regardless of bundle order. */
pre.file-preview-content {
@@ -46,7 +41,10 @@ pre.file-preview-content:not(.hljs) {
transform: translateY(-50%);
}
-/* base .office-preview-body / .office-preview-loading styles live in content_renderer.css */
-.note-detail-file > .office-preview-body {
- height: 100%;
+/* base .office-preview-body / .office-preview-loading styles live in content_renderer.css.
+ The unpadded wrapper is the scroll host (like .scrolling-container for text notes):
+ the scrollbar hugs the split edge and the body's padding scrolls with the document. */
+.note-detail-file:has(> .office-preview-body) {
+ overflow: auto;
+ padding: 0;
}