Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For VS Code what is the accepted alternative to the deprecated TextEditor.hide() function?

How does one close an editor programmatically in Visual Studio Code? The docs say TextEditor.hide() is deprecated and that we should "Use the command workbench.action.closeActiveEditor instead", but I can't find the workbench.action API.

like image 981
James Avatar asked Jun 07 '26 19:06

James


1 Answers

It's not really an "API", but an identifier for a command in the command palette (see keybindings.json for a list). An extension can invoke commands via executeCommand():

vscode.commands.executeCommand("workbench.action.closeActiveEditor");

This is equivalent to selecting the View: Close Editor command manually or pressing the associated shortcut:

like image 136
Gama11 Avatar answered Jun 10 '26 09:06

Gama11



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!