8

In Visual Studio Code, if you want to add a new file or folder under an existing folder, you need to first select it. However, selecting a folder will cause it to toggle between expanded and collapsed, which can be bothersome because it often makes you need to click the folder twice and because it can cause the file list to scroll around. Sometimes I want to select a folder that is already open without closing it. However, I have yet to find a way to do so.

Example:

I want to select pktest folder:
screenshot of pktest folder in Explorer, unselected and expanded

After selecting it, it gets collapsed and I need to open it again =(
screenshot of pktest folder in Explorer, selected but collapsed

Is it possible to select folders without collapsing or expanding them?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

6 Answers6

7

Coming soon (possibly in v1.51?), there is a commit see https://github.com/microsoft/vscode/issues/71994 that allows the ability to turn off the toggling open/close of a folder when you click on it. But it isn't in the Insiders' Build yet. This would be the setting:

"workbench.tree.expandOnFolderClick": false
Mark
  • 143,421
  • 24
  • 428
  • 436
  • 1
    This is now available in settings. (If you search for "expand" it currently comes up on top) – Pro Q Jun 04 '21 at 00:36
  • 1
    @ProQ Thanks for the comment, I'd have not found it looking for the setting name. – Nikki9696 Jul 07 '21 at 15:53
  • This doesn't seem to exist (or was changed). As of VS Code 1.69.0, there's only: `workbench.tree.expandMode` to set either `singleClick` or `doubleClick`. – Gino Mempin Jul 27 '22 at 14:18
3

Right click -> New File/New Folder

InterIRL
  • 64
  • 1
1

I struggled with the same thing. One option is Ctrl+Shift+E to select the Explorer, use the arrow keys to navigate to the target location, and then click the New File or New Folder button.

Another option is to change keybindings to improve the new file workflow, ndonohoe has a great answer in a different question describing remapping the new file command.

user6456942
  • 11
  • 1
  • 1
1

To just select objects (including folders) in the explorer view in VS Code here are the two ways I know.

If using mouse: Ctrl + left mouse click

If using keyboard: Ctrl + Shift + Enter

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
N.K.
  • 21
  • 5
0

In VS Code 1.52.0, they added a Tree: Expand Mode setting which

lets you control how folders expand in trees: using a single or a double-click

You can change that to "double-click"

"workbench.tree.expandMode": "doubleClick"

so that single-clicking on folder names won't auto-expand/collapse them.

Do note that:

// Controls how tree folders are expanded when clicking the 
folder > names. Note that some trees and lists might choose 
to ignore this > setting if it is not applicable.
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
0

Note that the workbench.tree.expandMode setting mentioned in Gino Mempin's answer will not work before VSCode 1.71 (Aug. 2022) for custom tree.

That settings comes from issues 95697 and commit 97646e1 .

But, as shown in "How to embrace workbench.tree.expandMode in TreeItem?", the workbench.tree.expandMode was never implemented for any extension tree.

Hence issue 158159 and PR 158160, release to VSCode insider today.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250