Skip to content

Commit

Permalink
Fix WebView reopening, tlaplus#167
Browse files Browse the repository at this point in the history
  • Loading branch information
alygin authored and lemmy committed Feb 19, 2021
1 parent de3d472 commit 257c61a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/checkResultView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ModelCheckResult, ModelCheckResultSource } from './model/check';
import { CMD_CHECK_MODEL_STOP, CMD_SHOW_TLC_OUTPUT, CMD_CHECK_MODEL_RUN_AGAIN } from './commands/checkModel';

// Cached HTML template for the WebView
let viewHtmlTemplate: string | undefined;
let viewHtml: string | undefined;
let viewPanel: vscode.WebviewPanel | undefined;
let currentSource: ModelCheckResultSource | undefined;
Expand Down Expand Up @@ -69,6 +70,7 @@ function createNewPanel() {
};
viewPanel.onDidDispose(() => {
viewPanel = undefined;
viewHtml = undefined;
});
viewPanel.webview.onDidReceiveMessage(message => {
if (message.command === 'init') {
Expand Down Expand Up @@ -101,13 +103,16 @@ function ensurePanelBody(extContext: vscode.ExtensionContext) {
if (!viewPanel) {
return;
}
if (!viewHtmlTemplate) {
const pagePath = path.join(extContext.extensionPath, 'resources', 'check-result-view.html');
viewHtmlTemplate = fs.readFileSync(pagePath, 'utf8');
}
if (!viewHtml) {
const resourcesDiskPath = vscode.Uri.file(
path.join(extContext.extensionPath, 'resources')
);
const resourcesPath = viewPanel.webview.asWebviewUri(resourcesDiskPath);
viewHtml = fs.readFileSync(path.join(extContext.extensionPath, 'resources', 'check-result-view.html'), 'utf8');
viewHtml = viewHtml
viewHtml = viewHtmlTemplate
.replace(/\${cspSource}/g, viewPanel.webview.cspSource)
.replace(/\${resourcesPath}/g, String(resourcesPath));
}
Expand Down

0 comments on commit 257c61a

Please sign in to comment.