(outputUri: vscode.Uri, filePath: string, title: string, cp: DisposableProcess | undefined, viewer: vscode.ViewColumn, resourceViewColumn: vscode.ViewColumn, autoRefresh: boolean)
| 368 | } |
| 369 | |
| 370 | private openPreview(outputUri: vscode.Uri, filePath: string, title: string, cp: DisposableProcess | undefined, viewer: vscode.ViewColumn, resourceViewColumn: vscode.ViewColumn, autoRefresh: boolean): void { |
| 371 | |
| 372 | const panel = vscode.window.createWebviewPanel( |
| 373 | 'previewRmd', |
| 374 | `Preview ${title}`, |
| 375 | { |
| 376 | preserveFocus: true, |
| 377 | viewColumn: viewer |
| 378 | }, |
| 379 | { |
| 380 | enableFindWidget: true, |
| 381 | enableScripts: true, |
| 382 | retainContextWhenHidden: true, |
| 383 | localResourceRoots: [vscode.Uri.file(tmpDir())], |
| 384 | }); |
| 385 | |
| 386 | panel.iconPath = new UriIcon('preview'); |
| 387 | |
| 388 | // Push the new rmd webview to the open proccesses array, |
| 389 | // to keep track of running child processes |
| 390 | // (primarily used in killing the child process, but also |
| 391 | // general state tracking) |
| 392 | const preview = new RMarkdownPreview( |
| 393 | title, |
| 394 | cp, |
| 395 | panel, |
| 396 | resourceViewColumn, |
| 397 | outputUri, |
| 398 | filePath, |
| 399 | this, |
| 400 | this.useCodeTheme, |
| 401 | autoRefresh |
| 402 | ); |
| 403 | this.previewStore.add(filePath, preview); |
| 404 | |
| 405 | // state change |
| 406 | panel.onDidDispose(() => { |
| 407 | // clear values |
| 408 | this.activePreview = this.activePreview?.preview === preview ? { filePath: null, preview: null, title: null } : this.activePreview; |
| 409 | void setContext('r.rmarkdown.preview.active', false); |
| 410 | this.previewStore.delete(filePath); |
| 411 | }); |
| 412 | |
| 413 | panel.onDidChangeViewState(({ webviewPanel }) => { |
| 414 | void setContext('r.rmarkdown.preview.active', webviewPanel.active); |
| 415 | if (webviewPanel.active) { |
| 416 | this.activePreview.preview = preview; |
| 417 | this.activePreview.filePath = filePath; |
| 418 | this.activePreview.title = title; |
| 419 | void setContext('r.rmarkdown.preview.autoRefresh', preview.autoRefresh); |
| 420 | } |
| 421 | }); |
| 422 | } |
| 423 | |
| 424 | private refreshPanel(preview: RMarkdownPreview): void { |
| 425 | void preview.refreshContent(this.useCodeTheme); |
no test coverage detected