(url: string)
| 17 | } |
| 18 | |
| 19 | async open(url: string): Promise<vscode.WebviewPanel> { |
| 20 | const resolved = await vscode.env.asExternalUri(vscode.Uri.parse(url)); |
| 21 | const resolvedUrl = resolved.toString(); |
| 22 | |
| 23 | const panel = vscode.window.createWebviewPanel( |
| 24 | "plannotator", |
| 25 | "Plannotator", |
| 26 | vscode.ViewColumn.One, |
| 27 | { enableScripts: true, retainContextWhenHidden: true }, |
| 28 | ); |
| 29 | panel.iconPath = vscode.Uri.file( |
| 30 | path.join(this.extensionPath, "images", "icon.png"), |
| 31 | ); |
| 32 | const origin = `${resolved.scheme}://${resolved.authority}`; |
| 33 | panel.webview.html = getHtml(resolvedUrl, origin); |
| 34 | |
| 35 | const messageSub = panel.webview.onDidReceiveMessage(async (raw: unknown) => { |
| 36 | const msg = raw as WebviewMessage; |
| 37 | if (msg.type === "plannotator-clipboard-write") { |
| 38 | await vscode.env.clipboard.writeText(msg.text ?? ""); |
| 39 | } else if (msg.type === "plannotator-clipboard-read") { |
| 40 | const text = await vscode.env.clipboard.readText(); |
| 41 | panel.webview.postMessage({ type: "plannotator-clipboard-data", id: msg.id, text }); |
| 42 | } |
| 43 | }); |
| 44 | |
| 45 | this.panels.add(panel); |
| 46 | panel.onDidDispose(() => { |
| 47 | messageSub.dispose(); |
| 48 | this.panels.delete(panel); |
| 49 | }); |
| 50 | return panel; |
| 51 | } |
| 52 | |
| 53 | closeAll(): void { |
| 54 | for (const panel of this.panels) { |
no test coverage detected