From 6c89d668fe01b44db9d33e7e84aed765a211c69f Mon Sep 17 00:00:00 2001 From: Yuri Karamian Date: Mon, 20 Jul 2026 02:17:38 +0200 Subject: [PATCH] Fix table sizing and headerless table persistence (#213) --- src/lib/components/Editor.svelte | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lib/components/Editor.svelte b/src/lib/components/Editor.svelte index 94690f5..d350abf 100644 --- a/src/lib/components/Editor.svelte +++ b/src/lib/components/Editor.svelte @@ -3228,10 +3228,11 @@ let changed = false; state.doc.descendants((node: any, pos: number) => { if (node.type.name === 'tableCell' || node.type.name === 'tableHeader') { - if (node.attrs.backgroundColor || (node.attrs.colspan && node.attrs.colspan > 1) || (node.attrs.rowspan && node.attrs.rowspan > 1)) { + if (node.attrs.backgroundColor || node.attrs.colwidth || (node.attrs.colspan && node.attrs.colspan > 1) || (node.attrs.rowspan && node.attrs.rowspan > 1)) { tr = tr.setNodeMarkup(pos, undefined, { ...node.attrs, backgroundColor: null, + colwidth: null, colspan: 1, rowspan: 1, }); @@ -3306,17 +3307,22 @@ case 'pageBreak': return '
\n'; case 'table': { - // Check if any cell has styling (background color) or if there are merged cells let hasStyling = false; + const firstRow = node.firstChild; + let hasHeaderRow = !!firstRow && firstRow.childCount > 0; + firstRow?.forEach((cell: any) => { + if (cell.type.name !== 'tableHeader') hasHeaderRow = false; + }); node.descendants((child: any) => { if (child.type.name === 'tableCell' || child.type.name === 'tableHeader') { if (child.attrs.backgroundColor) hasStyling = true; + if (child.attrs.colwidth) hasStyling = true; if (child.attrs.colspan && child.attrs.colspan > 1) hasStyling = true; if (child.attrs.rowspan && child.attrs.rowspan > 1) hasStyling = true; } return true; }); - if (hasStyling) { + if (hasStyling || !hasHeaderRow) { const tempDiv = document.createElement('div'); const frag = DOMSerializer.fromSchema(editor!.schema).serializeNode(node); tempDiv.appendChild(frag); @@ -3709,12 +3715,10 @@ // Clean up any leading double/triple slashes (URL parsing artifact) absPath = absPath.replace(/^\/{2,}/, '/'); absPath = absPath.replace(/^\/([A-Za-z]:\/)/, '$1').replace(/\\/g, '/'); - // Preserve note-relative paths, including parent-directory segments. const notePath = $activeNotePath; const vaultRoot = $appConfig?.active_vault?.replace(/\\/g, '/').replace(/\/$/, ''); if (vaultRoot && absPath.startsWith(vaultRoot + '/')) { const vaultRelative = absPath.substring(vaultRoot.length + 1); - // HelixNotes-managed attachments have explicit vault-root semantics. if (vaultRelative.startsWith('.helixnotes/')) return vaultRelative; if (notePath) { const normalizedNotePath = notePath.replace(/\\/g, '/'); @@ -4707,7 +4711,7 @@ if (resolved.node(d).type.name === 'table') { resolved.node(d).descendants((n: any) => { if (n.type.name === 'tableCell' || n.type.name === 'tableHeader') { - if (n.attrs.backgroundColor || (n.attrs.colspan > 1) || (n.attrs.rowspan > 1)) hasStyling = true; + if (n.attrs.backgroundColor || n.attrs.colwidth || (n.attrs.colspan > 1) || (n.attrs.rowspan > 1)) hasStyling = true; } return true; }); @@ -7020,7 +7024,7 @@
{#if tableContextMenu.hasStyling} - @@ -9660,7 +9664,7 @@ :global(.tiptap-wrapper .tiptap table) { border-collapse: collapse; - width: 100%; + width: auto; table-layout: fixed; overflow: hidden; }