Search code examples
visual-studio-code

How can I prevent VS Code from opening the Open Editors View when revealing in the Explorer a file that is not part of the current workspace?


I usually have the Open Editors pane toggled off. However I use a keyboard shortcut to "Reveal Active File in Explorer View" quite often while working. This navigates me to the file in my file tree most of the time, but sometimes I'm in a file that doesn't exist in the file tree then the open editors pane pops open like so.

In some random file and I hit the Reveal Active File in Explorer View command: in a screenshot file

Then I get the Open Editors panel: open editors pane shown

This is quite annoying because then I have to close the Open Editors pane manually once again.

Any ideas on how to stop the Open Editors pane from ever showing up?


Solution

  • UPDATE 2024-09-11 As mentioned below in comment the original answer does not work well.

    What I ended up doing instead, is resort to the answer above, spam escape key mindlessly. I also have bound escape to close global search and other modal-in-spirit panels.

    // keybindings.json
    [
       {
            "key": "escape",
            "command": "workbench.explorer.openEditorsView.toggleVisibility",
            "when": "workbench.explorer.openEditorsView.visible"
        },
        // ...
    ]
    

    ORIGINAL ANSWER

    With multi-command extension, I bind the hotkey to reveal the explorer to additionally hide the open editors

    // keybindings.json
    [
        {
            "key": "alt+f1",
            "command": "extension.multiCommand.execute",
            "args": {
                "sequence": [
                    "revealInExplorer",
                    "workbench.explorer.openEditorsView.removeView",
                ]
            },
            "when": "!view.workbench.explorer.fileView.visible"
        },
        {
            "key": "alt+f1",
            "command": "workbench.action.toggleSidebarVisibility",
            "when": "view.workbench.explorer.fileView.visible"
        },
    //  ...
    ]