From c548bac003a7071de0824e0af3c73fcf9bde87f2 Mon Sep 17 00:00:00 2001 From: JK Date: Thu, 4 Jun 2026 14:07:12 +0200 Subject: [PATCH] feat(row-layout): aggressively compress vertical spacing for row layout - Adds a `tightenColumn` helper to override and clear margins/paddings on all inner elements (paragraphs, math blocks, code wrappers, SVGs, MathJax containers). - Executes spacing compression at delayed intervals (0ms, 50ms, 150ms, 500ms) to ensure late-rendered asynchronous elements are properly shrunk. - Pulls surrounding paragraph text closer by setting the row element margin to `-0.5em 0`. - Ensures proper component cleanups via `ctx.addChild` and `destroy()` to prevent memory leaks. --- src/features/tikz/row-layout.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/features/tikz/row-layout.ts b/src/features/tikz/row-layout.ts index e2ca68b..e422800 100644 --- a/src/features/tikz/row-layout.ts +++ b/src/features/tikz/row-layout.ts @@ -19,6 +19,21 @@ function selectionAndRangeOverlap(selection: EditorSelection, rangeFrom: number, return false; } +function tightenColumn(colEl: HTMLElement) { + colEl.style.setProperty("margin-top", "0", "important"); + colEl.style.setProperty("margin-bottom", "0", "important"); + colEl.style.setProperty("padding-top", "0", "important"); + colEl.style.setProperty("padding-bottom", "0", "important"); + + const selectors = "p, .math, .math-block, pre, code, .block-language-tikz, mjx-container, svg, .cm-embed-block"; + colEl.querySelectorAll(selectors).forEach((el: HTMLElement) => { + el.style.setProperty("margin-top", "0", "important"); + el.style.setProperty("margin-bottom", "0", "important"); + el.style.setProperty("padding-top", "0", "important"); + el.style.setProperty("padding-bottom", "0", "important"); + }); +} + // ========================================== // 1. Reading View & PDF Export Post-Processor // ========================================== @@ -156,7 +171,7 @@ export const createRowLayoutProcessor = (plugin: LatexReferencer): MarkdownPostP rowEl.style.gap = "1.5rem"; rowEl.style.width = "100%"; rowEl.style.alignItems = "center"; - rowEl.style.margin = "1.5em 0"; + rowEl.style.margin = "-0.5em 0"; columnsMarkdown.forEach((colMarkdown) => { const colEl = rowEl.createEl("div", { cls: "latex-referencer-column" }); @@ -169,6 +184,12 @@ export const createRowLayoutProcessor = (plugin: LatexReferencer): MarkdownPostP const comp = new MarkdownRenderChild(colEl); ctx.addChild(comp); MarkdownRenderer.render(plugin.app, colMarkdown, colEl, ctx.sourcePath, comp) + .then(() => { + tightenColumn(colEl); + setTimeout(() => tightenColumn(colEl), 50); + setTimeout(() => tightenColumn(colEl), 150); + setTimeout(() => tightenColumn(colEl), 500); + }) .catch((err) => console.error("Latex Referencer: Failed to render column markdown", err)); }); @@ -223,7 +244,7 @@ class RowLayoutWidget extends WidgetType { rowEl.style.gap = "1.5rem"; rowEl.style.width = "100%"; rowEl.style.alignItems = "center"; - rowEl.style.margin = "1.5em 0"; + rowEl.style.margin = "-0.5em 0"; this.columnsMarkdown.forEach((colMarkdown) => { const colEl = rowEl.createEl("div", { cls: "latex-referencer-column" }); @@ -237,6 +258,12 @@ class RowLayoutWidget extends WidgetType { comp.load(); this.components.push(comp); MarkdownRenderer.render(this.plugin.app, colMarkdown, colEl, this.sourcePath, comp) + .then(() => { + tightenColumn(colEl); + setTimeout(() => tightenColumn(colEl), 50); + setTimeout(() => tightenColumn(colEl), 150); + setTimeout(() => tightenColumn(colEl), 500); + }) .catch((err) => console.error("Latex Referencer: Failed to render Live Preview column markdown", err)); });