简体   繁体   English

VSCode 的多行选项卡

[英]Multirow Tabs for VSCode

I commonly have 10+ tabs open per editor window which makes it tedious to scroll back and forth (or use ctrl+tab) to find the file I want.我通常在每个编辑器窗口中打开 10 个以上的选项卡,这使得来回滚动(或使用 ctrl+tab)查找我想要的文件变得乏味。

Is there any way to have the tabs wrap?有没有办法让标签包装?

Similar to Atom's multirow-tabs .类似于 Atom 的multirow-tabs

Update: Looks like it is a work in progress .更新:看起来它正在进行中

UPDATE Feb 2021: In-built support for tabs-wrapping in VSCode v1.53.0+ 2021 年 2 月更新:VSCode v1.53.0+ 中对标签包装的内置支持

  • Just set the workbench.editor.wrapTabs to true in the settings.只需在设置中将workbench.editor.wrapTabs设置为true
  • I still use my configuration mentioned below to make tabs smaller as per my usage.我仍然使用下面提到的配置来根据我的使用情况缩小标签。

UPDATED 28 March 2020 for VSCode v1.43.2 2020 年 3 月 28 日更新 VSCode v1.43.2

  • Fixed CSS for tab-close button修复了选项卡关闭按钮的 CSS
  • Added CSS for smaller bread-crumbs and acion-bar (at the right of tab-bar)为较小的面包屑和 acion-bar 添加了 CSS(在标签栏的右侧)

I do the following for multirow tabs in visual-studio-code (until there is official support or an easier solution):我对视觉工作室代码中的多行选项卡执行以下操作(直到有官方支持或更简单的解决方案):

STEP 1: Install the extension VSCode Custom CSS .第 1安装扩展VSCode Custom CSS (Check out the extension page for proper installation instruction. It's a bit of a hack as VSCode does not officially support altering internal CSS.) (查看扩展页面以获取正确的安装说明。由于 VSCode 不正式支持更改内部 CSS,这有点麻烦。)

STEP 2: Create a CSS file (say, "/home/user/vscode/custom.css" ) and add the following contents:第 2创建一个 CSS 文件(比如"/home/user/vscode/custom.css" )并添加以下内容:

 /* Following CSS to wrap the tab-bar into multiple rows: */ .tabs-and-actions-container > .monaco-scrollable-element { height: auto !important; } .tabs-and-actions-container > .monaco-scrollable-element > .tabs-container { height: auto !important; flex-wrap: wrap; } /* Following CSS to make the tabs thinner/smaller (so that they take lesser vertical space): */ .monaco-workbench .part.editor > .content .editor-group-container > .title .tabs-container > .tab { height: 25px; padding-left: 4px; font-size: 0.8em; /* smaller font-size for tab icons and label */ } .monaco-workbench .part.editor > .content .editor-group-container > .title .tabs-container > .tab .label-name { font-size: inherit !important; /* inherit updated font-size for label */ } /* Following CSS for smaller close button on tabs: */ .monaco-workbench .part.editor>.content .editor-group-container>.title .tabs-container>.tab>.tab-close { width: 20px; } .monaco-workbench .part.editor>.content .editor-group-container>.title .tabs-container>.tab>.tab-close .action-label { height: 12px; width: 12px; background-size: 12px; } .monaco-workbench .part.editor>.content .editor-group-container.active>.title .tabs-container>.tab>.tab-close .action-label.codicon { font-size: 12px; } /* OPTIONAL: Following CSS for smaller breadcrumbs (below tab-bar) */ .monaco-breadcrumbs { font-size:0.65em; opacity: 0.8; height:18px !important; } .tabs-breadcrumbs .breadcrumbs-control { height: 18px !important; } .monaco-workbench .symbol-icon.block { height: 8px; width: 8px; min-height: 8px; min-width: 14px; background-position: 50%; background-size: contain; } .breadcrumbs-control .monaco-breadcrumb-item:before { min-width: 12px !important; height: 12px !important; background-size: contain !important; } /* OPTIONAL: Following CSS for smaller action-bar (beside the tab-bar) with menu, split, etc. */ .monaco-workbench .part.editor>.content .editor-group-container>.title .editor-actions { height: 20px; padding:0; } .monaco-workbench .part.editor>.content .editor-group-container>.title .editor-actions .action-label, .monaco-workbench .part.editor>.content .editor-group-container>.title .title-actions .action-label { height: 20px; line-height: 20px; min-width: 14px; background-size: 8px; } .tabs-and-actions-container > .editor-actions > .monaco-toolbar > .monaco-action-bar > .actions-container { max-width:60px; flex-wrap:wrap; }

STEP 3: Point the extension to your custom CSS.第 3 步:将扩展指向您的自定义 CSS。 Open the VSCode settings.json [Ctrl+Shift+P > "Open Settings(JSON)"] and add the following lines (with your path to custom.css file):打开 VSCode settings.json [Ctrl+Shift+P > "Open Settings(JSON)"]并添加以下几行(带有 custom.css 文件的路径):

"vscode_custom_css.imports": [
    "file:///home/user/vscode/custom.css"
],
"vscode_custom_css.policy": true

STEP 4: Make sure you have gone through the VSCode Custom CSS extension's readme and enabled it properly.第 4确保您已阅读VSCode 自定义 CSS扩展的自述文件并正确启用它。 You may have to reload VSCode.您可能需要重新加载 VSCode。 Also, edit the CSS as per your preferences!此外,根据您的喜好编辑 CSS!

CREDIT: This solution (link to extension and the CSS to wrap tab-bar into multi-lines) was originally posted by Steven Laidlaw in this Github thread .信用:这个解决方案(链接到扩展和 CSS 将标签栏包装成多行)最初由Steven Laidlaw在这个Github 线程中发布 I just extended the CSS for smaller tabs.我只是为较小的选项卡扩展了 CSS。

That "work in progress" link provided refers to the Visual Studio IDE, which is separate from VSCode. 提供的“正在进行的工作”链接是指与VSCode分开的Visual Studio IDE。 The latest I've seen on this issue is found on the VSCode project's Github page , which essentially said it is not a planned feature for 2018 and closed the issue. 在VSCode项目的Github页面上找到了关于此问题的最新消息 ,该页面本质上说这不是2018年的计划功能,因此已解决此问题。

I'm not a fan of having to Ctrl+Tab or scroll through the tab menu either; 我也不喜欢必须按Ctrl + Tab或在选项卡菜单中滚动; the only other option I've come across so far is to use the "Open Editors" list : 到目前为止,我遇到的唯一其他选择是使用“打开编辑器”列表

Without Tabs, the OPEN EDITORS section of the File Explorer is a quick way to do file navigation. 如果没有选项卡,则文件浏览器的“打开编辑器”部分是进行文件导航的快速方法。

This requires using the mouse, but then so would taking advantage of a multi-row tab layout. 这需要使用鼠标,但是随后需要利用多行选项卡的布局。 You can resize it to give you more space and reorder the tabs if desired. 您可以调整它的大小以给您更多空间,并根据需要重新排列选项卡。

Significant progress has been made on this issue Allow tabs to wrap to multi-line and the feature is now in the Insiders' Build (and presumably in v1.53 Stable as it works well in my testing):在这个问题上取得了重大进展Allow tabs to wrap to multi-line and the feature is now in the Insiders' Build (大概在 v1.53 Stable 中,因为它在我的测试中运行良好):

包装标签演示

As seen in the demo, you can even drag tabs from one row to another.如演示中所示,您甚至可以将选项卡从一行拖到另一行。 There is currently no limit on the number of rows until the editor itself gets too small.目前没有行数限制,直到编辑器本身变得太小。

You enable this functionality with您可以通过以下方式启用此功能

workbench.editor.wrapTabs: true or workbench.editor.wrapTabs: true

Workbench > Editor: Wrap Tabs in the Settings gui. Workbench > Editor: Wrap Tabs在设置 gui 中Workbench > Editor: Wrap Tabs

A couple of notes from testing tab wrapping :测试标签包装的一些注意事项:

  • make sure you have configured workbench.editor.tabSizing: fit (this will make the last tab fill the entire row for a more homogeneous look when tabs wrap) [ed.确保您已配置workbench.editor.tabSizing: fit (这将使最后一个选项卡填充整行,以便在选项卡换行时看起来更均匀)[ed. note: you can still use shrink , it just doesn't look as nice]注意:您仍然可以使用shrink ,它只是看起来不那么好]

  • if the space for the editor or editor toolbar becomes too small, wrapping turns off automatically and turns on again when the size get's larger如果编辑器或编辑器工具栏的空间变得太小,环绕会自动关闭并在尺寸变大时再次打开

  • you can still drag and drop tabs around even when they wrap即使它们环绕,您仍然可以拖放标签

  • you can still pin a tab and it shows pinned in the beginning of the tabs你仍然可以固定一个标签,它显示在标签的开头

  • when tabs wrap, the tab.border color is not only applied to the right of each tab but also below to separate tabs from each other当标签包裹时,标签.BORDER颜色不仅应用于每个选项卡的右侧,而且在下面将彼此分开选项卡

Also, depending on your color theme, consider modifying these settings:此外,根据您的颜色主题,请考虑修改以下设置:

"workbench.colorCustomizations": {

  "tab.border": "#fff6",
  "titleBar.border": "#fff6",
  "editorGroupHeader.tabsBorder": "#647c64",
}

to set off the borders of each tab.来衬托每个标签的边框。



There is some hope for a second row of tabs - albeit with pinned tabs but still sounds pretty useful.第二排选项卡有一些希望 - 尽管带有固定选项卡,但听起来仍然非常有用。 See Pinned tabs: show them in a secondary tab row above others .请参阅固定选项卡:在其他选项卡上方的辅助选项卡行中显示它们 Added to the Backlog.添加到积压。

By the way, pinned tabs are coming to v1.46.顺便说一下,固定标签即将发布到 v1.46。 More on their functionality: v1.46 release notes: pinned tabs有关其功能的更多信息: v1.46 发行说明:固定选项卡

UPDATE: Version 1.53 includes wrap tabs !更新: 1.53 版包括换行标签

The new "Wrap Tabs" setting is a checkbox under File > Preferences > Settings > Workbench > Editor Management .新的“Wrap Tabs”设置是File > Preferences > Settings > Workbench > Editor Management下的复选框。

Alternatively, you can set paste the following into your settings.json: "workbench.editor.wrapTabs": true或者,您可以将以下内容粘贴到 settings.json 中: "workbench.editor.wrapTabs": true

Since multirow tabs are still not officialy supported in VSCode, I wanted to bring a feature request to your attention that I just posted on their github.由于 VSCode 仍不正式支持多行选项卡,我想提请您注意我刚刚发布在他们的 github 上的功能请求。 Instead of always wrapping tabs to a new row I propose to have them laid out on rows that are completely independent from each other.我建议将标签放在彼此完全独立的行上,而不是总是将标签换行到新行。 The user decides, they can mix short rows with long rows that still require scrolling.用户决定,他们可以将短行与仍需要滚动的长行混合在一起。 See the details here:在此处查看详细信息:

github.com/microsoft/vscode/issues/80510 github.com/microsoft/vscode/issues/80510

My proposed solution certainly requires more work than unceremoniously wrapping tabs to a new row but in return it lets the user organize their tabs in a way that could increase productivity.我提出的解决方案肯定比毫不客气地将选项卡包装到新行需要更多的工作,但作为回报,它可以让用户以一种可以提高生产力的方式组织他们的选项卡。

I just played with the vscode developer tools console, and looks like this CSS will be enough to do that if incorporated with an extension:我刚刚玩过 vscode 开发人员工具控制台,看起来这个 CSS 如果与扩展程序结合就足以做到这一点:

.tabs-and-actions-container .monaco-scrollable-element {
   height: auto;
} 
.tabs-and-actions-container .monaco-scrollable-element .tabs-container {
   flex-wrap: wrap; flex: 1 1 auto;
   height: auto;
}

You can add this code to file:///C:/Users/[username]/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.main.css file to use it until your application updates.您可以将此代码添加到file:///C:/Users/[username]/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.main.css文件以使用直到您的应用程序更新。

Note: When you add this to workbench.main.css file, VSCode will alert that the integrity of VScode is corrupted, ignore that message.注意:当您将其添加到workbench.main.css文件时,VSCode 将警告 VScode 的完整性已损坏,请忽略该消息。 VSCode will function as before because it's a CSS change (if any javascript doesn't use some positions of the tabs, or something else). VSCode 将像以前一样运行,因为它是 CSS 更改(如果任何 javascript 不使用选项卡的某些位置或其他内容)。

Otherwise as @Bene said, this is a restricted area by VSCode development team.否则正如@Bene 所说,这是 VSCode 开发团队的禁区。 They say:他们说:

Restrictions限制

There are certain restrictions we impose upon extensions.我们对扩展施加了某些限制。 Here are the restrictions and their purposes.以下是限制及其目的。

No DOM Access无 DOM 访问

Extensions have no access to the DOM of VS Code UI.扩展无法访问 VS Code UI 的 DOM。 You cannot write an extension that applies custom CSS to VS Code or adds an HTML element to VS Code UI.您不能编写将自定义 CSS 应用于 VS Code 或将 HTML 元素添加到 VS Code UI 的扩展。

At VS Code, we're continually trying to optimize use of the underlying web technologies to deliver an always available, highly responsive editor and we will continue to tune our use of the DOM as these technologies and our product evolve.在 VS Code,我们不断尝试优化底层 Web 技术的使用,以提供始终可用、响应迅速的编辑器,并且随着这些技术和我们产品的发展,我们将继续调整我们对 DOM 的使用。 To ensure that extensions cannot interfere with the stability and performance of VS Code, and that we can continue to improve the DOM of VS Code without breaking existing extensions, we run extensions in an Extension Host process and prevent direct access to the DOM.为了确保扩展不会干扰 VS Code 的稳定性和性能,并且我们可以在不破坏现有扩展的情况下继续改进 VS Code 的 DOM,我们在 Extension Host 进程中运行扩展,并防止直接访问 DOM。

@ https://code.visualstudio.com/api/extension-capabilities/overview#no-dom-access @ https://code.visualstudio.com/api/extension-capabilities/overview#no-dom-access

I have found/developed a solution to display pinned tabs in their own row.. It's an addition to what people might be using already, not the answer to this thread per se.我已经找到/开发了一个解决方案来在他们自己的行中显示固定选项卡..它是人们可能已经使用的内容的补充,而不是这个线程本身的答案。

Original reply on github : https://github.com/microsoft/vscode/issues/98160#issuecomment-989276052 github上的原始回复: https : //github.com/microsoft/vscode/issues/98160#issuecomment-989276052

  • vscode v1.62.3 vscode v1.62.3
  • extension: Custom CSS and JS Loader v6.0.2扩展: Custom CSS and JS Loader v6.0.2

settings.json

{
  "workbench.editor.wrapTabs": true,

  "git.decorations.enabled": false,
  "workbench.editor.decorations.badges": false,
  "workbench.editor.decorations.colors": false,

  "vscode_custom_css.imports": ["file:///C:/temp/VScode/custom.css"],
  "vscode_custom_css.policy": true
}

ps In config above I also disabled some git stuff from tabs to make them more readable.. not sure if it affects other places, use with caution. ps 在上面的配置中,我还禁用了选项卡中的一些git内容,以使它们更具可读性.. 不确定它是否会影响其他地方,请谨慎使用。

custom.css

.tabs-container {
  display: flex !important;
  flex-wrap: wrap !important;
  height: auto !important;
}

.tabs-container::before,
.tabs-container::after {
  content: "" !important;
  width: 100% !important;
  order: 1 !important;
}

.tab {
  display: flex !important;
}

.tab:not(.sticky) {
  order: 1 !important;
}

Result ( gif ):结果( gif ):

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM