diff --git a/src/vs/platform/contextview/browser/contextMenuHandler.ts b/src/vs/platform/contextview/browser/contextMenuHandler.ts index 6a39c62dbc0..836a08a9935 100644 --- a/src/vs/platform/contextview/browser/contextMenuHandler.ts +++ b/src/vs/platform/contextview/browser/contextMenuHandler.ts @@ -25,6 +25,7 @@ export class ContextMenuHandler { private $el: Builder; private menuContainerElement: HTMLElement; + private focusToReturn: HTMLElement; constructor(element: HTMLElement, contextViewService: IContextViewService, telemetryService: ITelemetryService, notificationService: INotificationService) { this.setContainer(element); @@ -53,6 +54,8 @@ export class ContextMenuHandler { return; // Don't render an empty context menu } + this.focusToReturn = document.activeElement as HTMLElement; + this.contextViewService.showContextView({ getAnchor: () => delegate.getAnchor(), canRelayout: false, @@ -110,6 +113,11 @@ export class ContextMenuHandler { } this.contextViewService.hideContextView(false); + + // Restore focus here + if (this.focusToReturn) { + this.focusToReturn.focus(); + } } private onDidActionRun(e: IRunEvent): void {