See the "Global UI contexts" section of the when-clause context docs. There's a workspaceFolderCount
when-clause that you can use. See also the sections on operators.
{
"key": "<your-keybinding>",
"when": "workspaceFolderCount > 0",
"command": "workbench.action.closeFolder",
},
{
"key": "<your-keybinding>",
"when": "workspaceFolderCount == 0",
"command": "workbench.action.quit", // or workbench.action.closeWindow
},
(I'm actually not sure what the difference between workbench.action.quit
and workbench.action.closeWindow
are).
Note: If you want to use ctrl/cmd+q, if you already have a default keybinding for ctrl/cmd+q for the workbench.action.quit
command, in which case I think you can just keep that and don't need to write one again.