VSCode 在文件中打开新视图 [英] VSCode Open new view into file

查看:63
本文介绍了VSCode 在文件中打开新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用拆分编辑器"选项将两个视图合并为一个文件.

We can use the "split editor" option to make two views into one file.

我正在寻找一个选项,可以像在 Sublime Text 中那样在单独的选项卡中打开同一个文件(打开文件的新视图).这可能吗?

I'm looking for an option to open the same file in separated tabs like I can do in Sublime Text (open new view of file). Is that possible?

注意:我想在不拆分视图的情况下执行此操作,因此同一个视图容器中的同一个文件应该有两个选项卡.

Note: I want to do this without splitting the view, so there should be two tabs for the same file within the same view container.

推荐答案

我找不到任何可以让您执行此操作的内置工具,也找不到市场中的现有扩展.我认为在 自定义扩展程序中自己实现重复标签"命令应该很简单a>,但结果是 VSCode 只允许在同一视图列中打开一次同一资源.

I couldn't find anything built-in that lets you do this, nor an existing extension in the marketplace. I thought it should be quite trivial to implement a "Duplicate Tab" command yourself in a custom extension, but it turns out VSCode only allows the same resource to be opened once within the same view column.

仍然可以在 Windows 或 macOS 上执行此操作,但只能通过滥用此错误:

It's still possible to do this on Windows or macOS, but only by abusing this bug:

不区分大小写/片段规范化文件路径的问题(macOS、Windows)#12448

扩展程序的代码如下所示:

Here's what the code for the extension looks like:

'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"
        }
    ]
},

这篇关于VSCode 在文件中打开新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆