简体   繁体   English

每次从vscode更改视图时如何获取当前选定的视图 API

[英]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

Code Example代码示例

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.

相关问题 更改模型后视图未更新 - View not updated when model changed 数据更改后,工具栏视图也不会改变吗? - Toolbar view is not changed when its data changed? 如何检测路由更改和Angular中的新视图替换 - How to detect when route changed and new view replaced in Angular 如何使用 typescript 在更改视图(如日视图或周视图)上获取剑道调度程序的当前视图? - How can i get kendo scheduler current view on change view like day view or week view using typescript? 如何在Angular 2中的html视图中显示api数据获取api - how to show api data in html view in Angular 2 get api VScode API为什么我不能获得当前行? - VScode API why can't I get the current line? 更改文本编辑器时如何修复 VScode 装订线指示器工件? - How to fix VScode gutter indicator artifacts when the text editor is changed? 开发 VSCode 扩展时获取当前活动文件的目录 - Get directory of Current active file when developing a VSCode extension 当用户在Angular 2中的视图上更改了某些内容时,如何检测Component中的更改? - How to detect changes in Component when user has changed something on the view in Angular 2? 如何在 angular 2 中从 localstorage 订阅项目,并在更改时获取值 - how to subscribe an item from localstorage in angular 2 and when changed, get value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM