Skip to content

Commit

Permalink
fix: avoid webview buttons show in unrelated extensions windows
Browse files Browse the repository at this point in the history
close #1611
  • Loading branch information
johnsoncodehk committed Jul 31, 2022
1 parent 0c6e940 commit 5c13561
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 5 additions & 5 deletions extensions/vscode-vue-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,11 @@
},
{
"command": "volar.action.selectElement",
"when": "activeEditor == WebviewEditor"
"when": "volarPreviewFocus"
},
{
"command": "volar.action.openInBrowser",
"when": "activeEditor == WebviewEditor"
"when": "volarPreviewFocus"
},
{
"command": "volar.selectTypeScriptVersion",
Expand All @@ -743,17 +743,17 @@
},
{
"command": "volar.action.selectElement",
"when": "activeEditor == WebviewEditor",
"when": "volarPreviewFocus",
"group": "navigation"
},
{
"command": "volar.action.openInBrowser",
"when": "activeEditor == WebviewEditor",
"when": "volarPreviewFocus",
"group": "navigation"
},
{
"command": "workbench.action.webview.reloadWebviewAction",
"when": "activeEditor == WebviewEditor",
"when": "volarPreviewFocus",
"group": "navigation"
}
],
Expand Down
20 changes: 20 additions & 0 deletions extensions/vscode-vue-language-features/src/features/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const enum PreviewType {
export async function register(context: vscode.ExtensionContext) {

const panels = new Set<vscode.WebviewPanel>();
let _activePreview: vscode.WebviewPanel | undefined;
let externalBrowserPanel: vscode.WebviewPanel | undefined;
let avoidUpdateOnDidChangeActiveTextEditor = false;
let updateComponentPreview: Function | undefined;
Expand Down Expand Up @@ -365,6 +366,7 @@ export async function register(context: vscode.ExtensionContext) {
enableFindWidget: true,
},
);
trackActive();

const panelContext: vscode.Disposable[] = [];

Expand Down Expand Up @@ -412,6 +414,24 @@ export async function register(context: vscode.ExtensionContext) {
}

return port;

function trackActive(): void {
panel.onDidChangeViewState(({ webviewPanel }) => {
setPreviewActiveContext(webviewPanel.active);
_activePreview = webviewPanel.active ? panel : undefined;
});

panel.onDidDispose(() => {
if (_activePreview === panel) {
setPreviewActiveContext(false);
_activePreview = undefined;
}
});
}

function setPreviewActiveContext(value: boolean) {
vscode.commands.executeCommand('setContext', 'volarPreviewFocus', value);
}
}

async function webviewEventHandler(message: any) {
Expand Down

0 comments on commit 5c13561

Please sign in to comment.