From 4a9d98b4d163fa9415bf28834beac1f24857a2b7 Mon Sep 17 00:00:00 2001 From: James Yu Date: Wed, 6 Sep 2023 10:30:19 +0100 Subject: [PATCH] Fix #4003 Regain focus after creating viewer tab --- src/components/viewer.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/viewer.ts b/src/components/viewer.ts index 8fecf44cb..ac7f781d7 100644 --- a/src/components/viewer.ts +++ b/src/components/viewer.ts @@ -167,15 +167,19 @@ export class Viewer { const editorGroup = configuration.get('view.pdf.tab.editorGroup') // Roughly translate editorGroup to vscode.ViewColumn let viewColumn: vscode.ViewColumn + let focusAction: string = '' if (editorGroup === 'current') { viewColumn = vscode.ViewColumn.Active } else if (editorGroup === 'right') { viewColumn = vscode.ViewColumn.Two + focusAction = 'workbench.action.focusLeftGroup' } else if (editorGroup === 'left') { viewColumn = vscode.ViewColumn.One + focusAction = 'workbench.action.focusRightGroup' } else { // Other locations are not supported by the editor open API -> use right panel as default viewColumn = vscode.ViewColumn.Two + focusAction = 'workbench.action.focusLeftGroup' } const pdfUri = vscode.Uri.file(pdfFile) const showOptions: vscode.TextDocumentShowOptions = { @@ -183,6 +187,9 @@ export class Viewer { preserveFocus: true } await vscode.commands.executeCommand('vscode.openWith', pdfUri, 'latex-workshop-pdf-hook', showOptions) + if (focusAction !== '') { + await vscode.commands.executeCommand(focusAction) + } } async openPdfInTab(pdfUri: vscode.Uri, tabEditorGroup: string, preserveFocus: boolean): Promise {