From 3d27e482a7d437ebe922fd595211a00086b20ec5 Mon Sep 17 00:00:00 2001 From: Scott Dover Date: Tue, 10 Oct 2023 14:19:01 -0400 Subject: [PATCH] Store panel references instead of html --- client/src/components/ResultPanel/ResultPanel.ts | 9 ++++++--- client/src/components/ResultPanel/index.ts | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/client/src/components/ResultPanel/ResultPanel.ts b/client/src/components/ResultPanel/ResultPanel.ts index 7f0d85c41..9b35ab66b 100644 --- a/client/src/components/ResultPanel/ResultPanel.ts +++ b/client/src/components/ResultPanel/ResultPanel.ts @@ -10,7 +10,7 @@ import { } from "../Helper/SettingHelper"; let resultPanel: WebviewPanel | undefined; -export const resultsHtml: Record = {}; +export const resultPanels: Record = {}; export interface ResultsContext { preventDefaultContextMenuItems: boolean; @@ -22,7 +22,6 @@ export const showResult = (html: string, uri?: Uri, title?: string) => { preventDefaultContextMenuItems: true, uuid: v4(), }; - resultsHtml[vscodeContext.uuid] = html; html = html // Inject vscode context into our results html body .replace( @@ -51,7 +50,10 @@ export const showResult = (html: string, uri?: Uri, title?: string) => { }, // Editor column to show the new webview panel in. {}, // Webview options. More on these later. ); - resultPanel.onDidDispose(() => (resultPanel = undefined)); + resultPanel.onDidDispose(() => { + resultPanel = undefined; + delete resultPanels[vscodeContext.uuid]; + }); } else { const editor = uri ? window.visibleTextEditors.find( @@ -67,4 +69,5 @@ export const showResult = (html: string, uri?: Uri, title?: string) => { ); } resultPanel.webview.html = html; + resultPanels[vscodeContext.uuid] = resultPanel; }; diff --git a/client/src/components/ResultPanel/index.ts b/client/src/components/ResultPanel/index.ts index 46c86450c..99dd40052 100644 --- a/client/src/components/ResultPanel/index.ts +++ b/client/src/components/ResultPanel/index.ts @@ -3,7 +3,7 @@ import { Disposable, Uri, commands, window, workspace } from "vscode"; import { SubscriptionProvider } from "../SubscriptionProvider"; -import { ResultsContext, resultsHtml } from "./ResultPanel"; +import { ResultsContext, resultPanels } from "./ResultPanel"; export class ResultPanelSubscriptionProvider implements SubscriptionProvider { getSubscriptions(): Disposable[] { @@ -11,8 +11,8 @@ export class ResultPanelSubscriptionProvider implements SubscriptionProvider { commands.registerCommand( "SAS.saveHTML", async (context: ResultsContext) => { - const html = resultsHtml[context.uuid] || ""; - if (!html) { + const panel = resultPanels[context.uuid] || undefined; + if (!panel) { return; } const uri = await window.showSaveDialog({ @@ -23,7 +23,10 @@ export class ResultPanelSubscriptionProvider implements SubscriptionProvider { return; } - await workspace.fs.writeFile(uri, new TextEncoder().encode(html)); + await workspace.fs.writeFile( + uri, + new TextEncoder().encode(panel.webview.html), + ); }, ), ];