diff --git a/scripts/testing/pastedCodeCardSizing.source.test.mjs b/scripts/testing/pastedCodeCardSizing.source.test.mjs index a7a12a3c..70c13306 100644 --- a/scripts/testing/pastedCodeCardSizing.source.test.mjs +++ b/scripts/testing/pastedCodeCardSizing.source.test.mjs @@ -58,6 +58,7 @@ test("retired APIs, changed files and closing views cannot resize a replacement }); test("missing or detached previews have a bounded wait and no resize side effects", async () => { for (const configure of [f => f.view.excalidrawAPI = null, f => f.view.file = null, f => f.view.getEmbeddableLeafElementById = () => null, + f => f.view.getEmbeddableLeafElementById = () => ({ leaf: { view: { containerEl: f.container } } }), f => f.container.isConnected = false, f => f.container.ownerDocument = {}, f => f.container.querySelector = () => null, f => f.container.getBoundingClientRect = () => ({ top: 0, width: 0 }), f => f.pre.getBoundingClientRect = () => ({ bottom: 0, height: 0 })]) { await exercise(configure, f => { diff --git a/src/view/managers/pastedCodeCardSizing.ts b/src/view/managers/pastedCodeCardSizing.ts index bc5c82f7..bedfca0a 100644 --- a/src/view/managers/pastedCodeCardSizing.ts +++ b/src/view/managers/pastedCodeCardSizing.ts @@ -37,7 +37,9 @@ export async function fitPastedCodeBlockCard( return; } const host = view.getEmbeddableLeafElementById(id); - const container = host?.node?.containerEl ?? host?.leaf?.view?.containerEl; + // A fallback workspace leaf can render the whole drawing note, including + // other code blocks. Only the native section node identifies this card. + const container = host?.node?.containerEl; const preview = container?.querySelector(".markdown-preview-view"); const pre = preview?.querySelector("pre"); if (container?.isConnected && container.ownerDocument === view.ownerDocument && pre) {