如何将所有选项卡在视觉工作室代码窗口中以作为文件名的数组?

发布于 2025-02-10 17:34:42 字数 78 浏览 3 评论 0原文

我目前正在寻找可以让我查看Visual Studio代码编辑器(1.TXT,2.TXT,3.TXT)中的所有选项卡的呼叫,例如,在数组中返回。

I am currently looking to find the call that will allow me to see all the tabs in a Visual Studio Code editor (1.txt, 2.txt, 3.txt) being returned back in an array for example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不会写诗 2025-02-17 17:34:42
const tabArray = vscode.window.tabGroups.all;

将返回一组编辑组。然后,在每个编辑器组(或“ TabGroup”)中,您可以使用其选项卡数组:

const firstGroupOfTabs = tabArray[0].tabs;

const firstTabName = firstGroupOfTabs[0].label;

or 

const firstTabUri = firstGroupOfTabs[0].input.uri;  // gives you a uri if you need the full path - for most, but not all, editor types

因此,您必须通过tabgroups.all进行循环以获取所有文件名。这样做的一个示例:

const tabArray = tabGroupArray.flatMap(group => group.tabs.map(tab => tab.label));

为了使此键入更友好,请尝试以下操作:

  const tabArray: ReadonlyArray<vscode.TabGroup> = vscode.window.tabGroups.all;
  const firstGroupOfTabs: ReadonlyArray<vscode.Tab> = tabArray[0].tabs;
  
  let firstTabUri: vscode.Uri;  
  if (firstGroupOfTabs[0].input instanceof vscode.TabInputText) firstTabUri = firstGroupOfTabs[0].input.uri;

在这里,我将input narry缩小到vscode.tabinputtext,因为某些tab.input为编辑人员甚至没有uri成员。如果您对其他tab.input s感兴趣,则可以为它们范围缩小,也可以制作联合类型来简化它。

const tabArray = vscode.window.tabGroups.all;

will return an array of editor groups. And then within each editor group (or "tabGroup") you can get an array of its tabs with:

const firstGroupOfTabs = tabArray[0].tabs;

const firstTabName = firstGroupOfTabs[0].label;

or 

const firstTabUri = firstGroupOfTabs[0].input.uri;  // gives you a uri if you need the full path - for most, but not all, editor types

So you will have to do a loop through the tabGroups.all to get all the fileNames. One example of doing so:

const tabArray = tabGroupArray.flatMap(group => group.tabs.map(tab => tab.label));

To make this more typescript-friendly, try this:

  const tabArray: ReadonlyArray<vscode.TabGroup> = vscode.window.tabGroups.all;
  const firstGroupOfTabs: ReadonlyArray<vscode.Tab> = tabArray[0].tabs;
  
  let firstTabUri: vscode.Uri;  
  if (firstGroupOfTabs[0].input instanceof vscode.TabInputText) firstTabUri = firstGroupOfTabs[0].input.uri;

Here I narrowed the input to vscode.TabInputText because some of the Tab.input's for editors don't even have a uri member. If you are interested in other Tab.input's you can narrow for those or possibly make a union type to simplify it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文