Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable the "undo command for file operations in Explorer" feature in VS Code

Something that really bugs me in recent versions of VSCode is this feature to undo file operations in the file explorer. Apparently this is a new feature since v1.52 (November 2020) https://code.visualstudio.com/updates/v1_52 .

This sometimes causes files that I previously created to disappear because I accidentally press cmd+z in the file explorer instead of the file editor. I do not want this, because it messes heavily with my workflow and it's just generally very annoying that files get deleted which I don't want deleted. So I would like to disable it but I can't find in the settings where to disable this functionality. Do you know where / if I can do this?

like image 826
mivd Avatar asked Jan 30 '21 10:01

mivd


2 Answers

Good News Everyone

A setting has just been added to the Insiders Build v1.64 to give better control or disable undo operations on files:

Explorer: Enable Undo

Controls how the Explorer participates in undoing file and folder edits

It defaults to true though so you might want to change it to false. So that if you do a undo operation when a file or folder has focus in the Explorer, you will get a warning confirmation dialog.

This new setting should be in Stable v1.64 early February, 2022.

Explorer Undo: Confirm/Enable Undo

The file explorer has long supported an undo stack to revert file and folder edits. This iteration we've added prompts to make more explicit what actions an undo in the explorer will perform, and provided a setting to disable undo in the explorer entirely (explorer.enableUndo). By default the explorer will now prompt before all potentially destructive actions ("explorer.confirmUndo": "default"), but this can be changed to the old behavior ("light"), or "verbose", to prompt before all actions.

  • from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_64.md#explorer-undo-confirmenable-undo

Older Answers:

I don't see a relevant setting but you could do this so that undo only works when you have editorFocus (in your keybindings.json):

{
  "key": "ctrl+z",
  "command": "undo",
  "when": "editorFocus"
},
{
  "key": "ctrl+z",
  "command": "-undo"
}

As you probably know, v1.53 is at least adding a confirmation dialog for undo operations in the Explorer, see v1.53 release notes confirmation dialogs.

If a user tries to quit VS Code while there is a file operation in progress, we now show a confirmation dialog. We also show a confirmation dialog for destructive undo operations from the Explorer.

It isn't a setting to prevent even trying to do it, but does provide some protection.

like image 166
Mark Avatar answered Oct 20 '22 00:10

Mark


You need to make the command only trigger on text input focus by right-clicking on the undo command entry in the keyboard shortcut settings and adding or changing the "when" field to "textInputFocus".

You can see how to change keyboard settings here: https://code.visualstudio.com/docs/getstarted/keybindings

like image 44
Opeyemi Olarewaju Avatar answered Oct 19 '22 22:10

Opeyemi Olarewaju