mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Update to target VS Code 1.25+
This commit is contained in:
@ -10,12 +10,12 @@ Demonstrates VS Code's [webview API](https://code.visualstudio.com/docs/extensio
|
||||
- Sending messages from a webview to an extension.
|
||||
- Using a basic content security policy.
|
||||
- Webview lifecycle and handling dispose.
|
||||
- Saving and restoring state when the panel goes into the background. (Requires VS Code 1.25+)
|
||||
- Serialization and persistence across VS Code reboots. (Requires VS Code 1.25+)
|
||||
- Saving and restoring state when the panel goes into the background.
|
||||
- Serialization and persistence across VS Code reboots.
|
||||
|
||||
## Running the example
|
||||
|
||||
- Open this example in VS Code 1.23+
|
||||
- Open this example in VS Code 1.25+
|
||||
- `npm install`
|
||||
- `npm run watch` or `npm run compile`
|
||||
- `F5` to start debugging
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
const vscode = acquireVsCodeApi();
|
||||
|
||||
const oldState = vscode.getState && vscode.getState();
|
||||
const oldState = vscode.getState();
|
||||
|
||||
const counter = document.getElementById('lines-of-code-counter');
|
||||
console.log(oldState);
|
||||
@ -14,7 +14,7 @@
|
||||
counter.textContent = currentCount++;
|
||||
|
||||
// Update state
|
||||
vscode.setState && vscode.setState({ count: currentCount });
|
||||
vscode.setState({ count: currentCount });
|
||||
|
||||
// Alert the extension when the cat introduces a bug
|
||||
if (Math.random() < Math.min(0.001 * currentCount, 0.05)) {
|
||||
|
||||
714
webview-sample/package-lock.json
generated
714
webview-sample/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@
|
||||
"version": "0.0.1",
|
||||
"publisher": "ms-vscode",
|
||||
"engines": {
|
||||
"vscode": "^1.23.0"
|
||||
"vscode": "^1.25.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
|
||||
@ -19,10 +19,9 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
}));
|
||||
|
||||
// Serializers only introduced in VS Code 1.25+
|
||||
if ((vscode.window as any).registerWebviewPanelSerializer) {
|
||||
if (vscode.window.registerWebviewPanelSerializer) {
|
||||
// Make sure we register a serilizer in activation event
|
||||
(vscode.window as any).registerWebviewPanelSerializer(CatCodingPanel.viewType, {
|
||||
vscode.window.registerWebviewPanelSerializer(CatCodingPanel.viewType, {
|
||||
async deserializeWebviewPanel(webviewPanel: vscode.WebviewPanel, state: any) {
|
||||
console.log(`Got state: ${state}`);
|
||||
CatCodingPanel.revive(webviewPanel, context.extensionPath);
|
||||
@ -125,6 +124,8 @@ class CatCodingPanel {
|
||||
}
|
||||
|
||||
private _update() {
|
||||
|
||||
const z = 1 + 2;
|
||||
// Vary the webview's content based on where it is located in the editor.
|
||||
switch (this._panel.viewColumn) {
|
||||
case vscode.ViewColumn.Two:
|
||||
|
||||
Reference in New Issue
Block a user