Search code examples
visual-studio-code

How to close file explorer when opening a file?


I want to customize my vscode for the keyboard only experience (sort-of). Right now, if I open my file explorer and select via the arrow keys the needed file and press enter - it opens that file, focuses the editor (explorer gets unfocused) - but it does not close the file explorer.

So I need to press my combination to focus the explorer back, and then press that again - to close the explorer and focus back the editor.

My question is - how to close the explorer when I open a selected file?

I tried to find the command that is responsible for opening a new file, or an event, but did not find any solution...


Solution

  • I found the solution which worked for myself. there is explorer.openAndPassFocus. so this command worked for me

    {
        "key": "enter",
        "command": "runCommands",
        "when": "filesExplorerFocus && foldersViewVisible && !explorerResourceIsFolder && !inputFocus",
        "args": {
            "commands": [
                "explorer.openAndPassFocus",
                "workbench.action.focusActiveEditorGroup",
                "workbench.action.toggleSidebarVisibility"
            ]
        }
    }