我们可以使用“分割编辑器”选项将两个视图合并为一个文件。
我正在寻找一种选项,可以像在Sublime Text中那样在不同的标签页中打开同一个文件。这个可能吗?
注意:我想要做到这一点而不需要拆分视图,所以应该在同一个视图容器中有两个用于同一文件的标签页。
我们可以使用“分割编辑器”选项将两个视图合并为一个文件。
我正在寻找一种选项,可以像在Sublime Text中那样在不同的标签页中打开同一个文件。这个可能吗?
注意:我想要做到这一点而不需要拆分视图,所以应该在同一个视图容器中有两个用于同一文件的标签页。
我无法找到任何内置的功能或者现有市场扩展能够实现这一点。我认为自己可以很容易地在自定义扩展中实现“Duplicate Tab”命令,但是事实证明VSCode只允许在同一视图列中打开相同资源一次。
在Windows或macOS上仍然有可能实现这一点,但只能通过利用这个bug来进行:
Issues with not case/fragment-normalizing file paths (macOS, Windows) #12448
这是扩展的代码:
'use strict';
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand("duplicateTab", () => {
var activeEditor = vscode.window.activeTextEditor;
if (activeEditor == null) {
return;
}
// HACK!
const sameFileNameButDifferent = activeEditor.document.fileName.toUpperCase();
vscode.workspace.openTextDocument(sameFileNameButDifferent).then(document => {
vscode.window.showTextDocument(document, {preview: false});
});
});
}
package.json
文件中:"contributes": {
"commands": [
{
"title": "Duplicate Tab",
"command": "duplicateTab"
}
]
},