Jos Verlinde
Jos Verlinde

Reputation: 1697

how can I reset focus to the active editor?

In a vscode extension the focus is (intentionally) switched to a custom terminal, but in some cases I want the focus to return to the last active editor window. I have not found a method to achieve that reliably.

The following does not change the focus from the terminal to the code editor:

vscode.commands.executeCommand( "workbench.action.focusActiveEditorGroup" )  

The only workaround that mostly works is

vscode.commands.executeCommand( 'workbench.action.focusNextGroup') 
vscode.commands.executeCommand( 'workbench.action.focusPreviousGroup') 

however, in some cases the focus is not moved to the next group, but not back (possibly timing related).

Is there a better way to achieve this?

Upvotes: 4

Views: 1399

Answers (1)

Gama11
Gama11

Reputation: 34158

Calling showTextDocument() on the active editor's document will focus it:

vscode.window.showTextDocument(vscode.window.activeTextEditor.document)

Upvotes: 4

Related Questions