[英]How to get the current selected view everytime when view is changed from vscode API
I've added a new view in vscode while making an extension.我在进行扩展时在 vscode 中添加了一个新视图。
I want to run a function everytime when this view is opened.每次打开此视图时,我都想运行 function。
Is there any vscode method to run a function everytime this view is opened or when user come on this view.每次打开此视图或用户进入此视图时,是否有任何 vscode 方法运行 function。
I think you're looking for onDidChangeActiveTextEditor
我认为您正在寻找
onDidChangeActiveTextEditor
const vscode = require('vscode');
function runFunction() {
// Your code here
}
vscode.window.onDidChangeActiveTextEditor(event => {
if (event.document.uri.scheme === 'your-view-scheme') {
runFunction();
}
});
If your view is a TreeView
, you can listen to its visibility:如果您的视图是
TreeView
,您可以听取它的可见性:
const treeViewVisibilityListener = this.tabView.onDidChangeVisibility(async event => {
console.log("here");
});
context.subscriptions.push(treeViewVisibilityListener);
event
will have the values {visible: true}
or {visible: false}
depending on whether it was opened or not. event
将具有值{visible: true}
或{visible: false}
取决于它是否被打开。 It also works for when the view is hidden or unhidden from the Activity Bar or Panel or Secondary Bar - depending on where the user moves it.它也适用于视图从活动栏或面板或辅助栏隐藏或取消隐藏的情况 - 取决于用户移动它的位置。
If your view is a Webview
you can use the same .onDidChangeVisibility
listener.如果您的视图是
Webview
,您可以使用相同的.onDidChangeVisibility
侦听器。
These do not fire if the View clicked on/revealed is not yours.如果点击/显示的视图不是您的,则这些不会触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.