From 371932e0852c82992e45073db106e0caa477347c Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 4 Oct 2023 16:21:18 +0200 Subject: [PATCH] More iframe height fixing --- web/cm_plugins/fenced_code.ts | 3 ++- web/components/panel_html.ts | 13 ++++++++----- web/components/widget_sandbox_iframe.ts | 1 - 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/web/cm_plugins/fenced_code.ts b/web/cm_plugins/fenced_code.ts index 1dfb4b00..27c99f98 100644 --- a/web/cm_plugins/fenced_code.ts +++ b/web/cm_plugins/fenced_code.ts @@ -23,6 +23,7 @@ class IFrameWidget extends WidgetType { } toDOM(): HTMLElement { + const from = this.from; const iframe = createWidgetSandboxIFrame( this.editor, this.bodyText, @@ -31,7 +32,7 @@ class IFrameWidget extends WidgetType { switch (message.type) { case "blur": this.editor.editorView.dispatch({ - selection: { anchor: this.from }, + selection: { anchor: from }, }); this.editor.focus(); diff --git a/web/components/panel_html.ts b/web/components/panel_html.ts index 446653a2..ab53ed85 100644 --- a/web/components/panel_html.ts +++ b/web/components/panel_html.ts @@ -20,6 +20,9 @@ self.syscall = async (name, ...args) => { }); }; +let oldHeight = undefined; +let heightChecks = 0; + window.addEventListener("message", (message) => { const data = message.data; switch (data.type) { @@ -35,6 +38,11 @@ window.addEventListener("message", (message) => { console.error("Error evaling script", e); } } + setTimeout(() => { + oldHeight = undefined; + heightChecks = 0; + updateHeight(); + }); break; case "syscall-response": { @@ -65,8 +73,6 @@ function api(obj) { window.parent.postMessage(obj, "*"); } -let oldHeight = undefined; -let heightChecks = 0; function updateHeight() { const body = document.body, html = document.documentElement; let height = Math.max(body.offsetHeight, html.offsetHeight); @@ -82,9 +88,6 @@ function updateHeight() { setTimeout(updateHeight, 100); } } -setTimeout(() => { - updateHeight(); -}); function loadJsByUrl(url) { const script = document.createElement("script"); diff --git a/web/components/widget_sandbox_iframe.ts b/web/components/widget_sandbox_iframe.ts index 423ffb10..048d6a38 100644 --- a/web/components/widget_sandbox_iframe.ts +++ b/web/components/widget_sandbox_iframe.ts @@ -10,7 +10,6 @@ export function createWidgetSandboxIFrame( ) { const iframe = document.createElement("iframe"); iframe.srcdoc = panelHtml; - // iframe.style.height = "150px"; const messageListener = (evt: any) => { (async () => {