From b5c867ce98b6ca575a11a6c5f838c7e22d05fc0b Mon Sep 17 00:00:00 2001 From: Scott Dover Date: Wed, 18 Oct 2023 13:54:58 -0400 Subject: [PATCH] Use view type to store result panels --- .../src/components/ResultPanel/ResultPanel.ts | 29 +++++++++---------- client/src/components/ResultPanel/index.ts | 6 ++-- package.json | 2 +- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/client/src/components/ResultPanel/ResultPanel.ts b/client/src/components/ResultPanel/ResultPanel.ts index 9b35ab66b..9dd5aeebe 100644 --- a/client/src/components/ResultPanel/ResultPanel.ts +++ b/client/src/components/ResultPanel/ResultPanel.ts @@ -12,21 +12,14 @@ import { let resultPanel: WebviewPanel | undefined; export const resultPanels: Record = {}; -export interface ResultsContext { - preventDefaultContextMenuItems: boolean; - uuid: string; -} - export const showResult = (html: string, uri?: Uri, title?: string) => { - const vscodeContext: ResultsContext = { - preventDefaultContextMenuItems: true, - uuid: v4(), - }; html = html // Inject vscode context into our results html body .replace( " { } if (!singlePanel || !resultPanel) { + const resultPanelId = `SASResultPanel-${v4()}`; resultPanel = window.createWebviewPanel( - "SASResultPanel", // Identifies the type of the webview. Used internally + resultPanelId, // Identifies the type of the webview. Used internally title, // Title of the panel displayed to the user { preserveFocus: true, @@ -50,10 +44,13 @@ 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; - delete resultPanels[vscodeContext.uuid]; - }); + resultPanel.onDidDispose( + ((id) => () => { + delete resultPanels[id]; + resultPanel = undefined; + })(resultPanelId), + ); + resultPanels[resultPanelId] = resultPanel; } else { const editor = uri ? window.visibleTextEditors.find( @@ -69,5 +66,5 @@ export const showResult = (html: string, uri?: Uri, title?: string) => { ); } resultPanel.webview.html = html; - resultPanels[vscodeContext.uuid] = resultPanel; + console.log(resultPanels); }; diff --git a/client/src/components/ResultPanel/index.ts b/client/src/components/ResultPanel/index.ts index 99dd40052..9db4d6681 100644 --- a/client/src/components/ResultPanel/index.ts +++ b/client/src/components/ResultPanel/index.ts @@ -3,15 +3,15 @@ import { Disposable, Uri, commands, window, workspace } from "vscode"; import { SubscriptionProvider } from "../SubscriptionProvider"; -import { ResultsContext, resultPanels } from "./ResultPanel"; +import { resultPanels } from "./ResultPanel"; export class ResultPanelSubscriptionProvider implements SubscriptionProvider { getSubscriptions(): Disposable[] { return [ commands.registerCommand( "SAS.saveHTML", - async (context: ResultsContext) => { - const panel = resultPanels[context.uuid] || undefined; + async (context: { webview: string }) => { + const panel = resultPanels[context.webview] || undefined; if (!panel) { return; } diff --git a/package.json b/package.json index 238a7571f..8249de29c 100644 --- a/package.json +++ b/package.json @@ -610,7 +610,7 @@ "webview/context": [ { "command": "SAS.saveHTML", - "when": "webviewId == 'SASResultPanel'" + "when": "webviewId =~ /SASResultPanel-/" } ], "view/title": [