Skip to content

Build your personal knowledge base with Trilium Notes

fix(presentation): keep a table visible while editing its slide

Elian Doran39452dbaf658
diff --git a/apps/client/src/widgets/collections/presentation/fit.ts b/apps/client/src/widgets/collections/presentation/fit.ts
index 2f32535007..1005e884ee 100644
--- a/apps/client/src/widgets/collections/presentation/fit.ts
+++ b/apps/client/src/widgets/collections/presentation/fit.ts
@@ -1,4 +1,9 @@
const MAX_FIT_ATTEMPTS = 8;
+/**
+ * The least share of a proportional shrink that a zoom step must take off the overflow. Below it the
+ * overflow holds about the same share of the slide at any zoom, and no zoom makes the content fit.
+ */
+const MIN_RELATIVE_SLOPE = 0.1;
/**
* Fits each observed slide content again whenever its size changes: an image or a font loads, the theme
@@ -29,6 +34,8 @@ function measureSize(element: HTMLElement) {
*
* Some lengths (percentages, container query units) do not scale with `zoom`, so the content is measured
* again after each zoom. The overflow is close to linear in the zoom, so each next zoom is a secant step.
+ * Zooming stops when it barely shrinks the overflow, as for the UI of a table widget, which reaches past a
+ * full-width table by the same share at any zoom.
*/
export function fitSlideContent(content: HTMLElement) {
content.style.zoom = "";
@@ -42,9 +49,10 @@ export function fitSlideContent(content: HTMLElement) {
if (overflow <= 1) break;
const slope = (previous.overflow - overflow) / (previous.scale - scale);
+ if (slope < MIN_RELATIVE_SLOPE * overflow / scale) break;
const next = scale - (overflow - 1) / slope;
previous = { scale, overflow };
- scale = slope > 0 && next > 0 ? next : scale / overflow;
+ scale = next > 0 ? next : scale / overflow;
}
}
diff --git a/apps/client/src/widgets/collections/presentation/index.spec.ts b/apps/client/src/widgets/collections/presentation/index.spec.ts
index 0fa2cb1c55..1297ff290f 100644
--- a/apps/client/src/widgets/collections/presentation/index.spec.ts
+++ b/apps/client/src/widgets/collections/presentation/index.spec.ts
@@ -35,6 +35,14 @@ describe("fitSlideContent", () => {
expect(Number(content.style.zoom)).toBeCloseTo(0.5);
expect(Number(content.style.zoom) + 0.5).toBeLessThanOrEqual(1);
});
+
+ it("stops zooming out when the zoom barely shrinks the overflow", () => {
+ // A table editor's column resizer, 3px past a full-width table, overflows by the same share at
+ // any zoom; the secant step would place the fit at a zoom of almost nothing.
+ const content = buildContent({ width: zoom => 1 + 0.00234 * zoom });
+ fitSlideContent(content);
+ expect(Number(content.style.zoom)).toBeGreaterThan(0.99);
+ });
});
describe("createFitObserver", () => {