Make previewManager implement WebviewEditorProvider directly

This commit is contained in:
Matt Bierner
2019-11-21 20:36:39 -08:00
parent f085deb2e0
commit aaa01eac73
2 changed files with 6 additions and 12 deletions
+1 -7
View File
@@ -23,13 +23,7 @@ export function activate(context: vscode.ExtensionContext) {
const previewManager = new PreviewManager(extensionRoot, sizeStatusBarEntry, binarySizeStatusBarEntry, zoomStatusBarEntry);
context.subscriptions.push(vscode.window.registerWebviewEditorProvider(
PreviewManager.viewType,
{
async resolveWebviewEditor({ resource }, editor: vscode.WebviewPanel): Promise<vscode.WebviewEditorCapabilities> {
return previewManager.resolve(resource, editor);
}
}));
context.subscriptions.push(vscode.window.registerWebviewEditorProvider(PreviewManager.viewType, previewManager));
context.subscriptions.push(vscode.commands.registerCommand('imagePreview.zoomIn', () => {
previewManager.activePreview?.zoomIn();
+5 -5
View File
@@ -13,7 +13,7 @@ import { BinarySizeStatusBarEntry } from './binarySizeStatusBarEntry';
const localize = nls.loadMessageBundle();
export class PreviewManager {
export class PreviewManager implements vscode.WebviewEditorProvider {
public static readonly viewType = 'imagePreview.previewEditor';
@@ -27,11 +27,11 @@ export class PreviewManager {
private readonly zoomStatusBarEntry: ZoomStatusBarEntry,
) { }
public resolve(
resource: vscode.Uri,
public async resolveWebviewEditor(
input: { readonly resource: vscode.Uri, },
webviewEditor: vscode.WebviewPanel,
): vscode.WebviewEditorCapabilities {
const preview = new Preview(this.extensionRoot, resource, webviewEditor, this.sizeStatusBarEntry, this.binarySizeStatusBarEntry, this.zoomStatusBarEntry);
): Promise<vscode.WebviewEditorCapabilities> {
const preview = new Preview(this.extensionRoot, input.resource, webviewEditor, this.sizeStatusBarEntry, this.binarySizeStatusBarEntry, this.zoomStatusBarEntry);
this._previews.add(preview);
this.setActivePreview(preview);