Skip to content

Commit

Permalink
Fix hover escape key focus impl
Browse files Browse the repository at this point in the history
  • Loading branch information
rzhao271 committed Nov 21, 2022
1 parent e43bf31 commit 67271fc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/vs/workbench/services/hover/browser/hoverWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class HoverWidget extends Widget {
private readonly _hoverContainer: HTMLElement;
private readonly _target: IHoverTarget;
private readonly _linkHandler: (url: string) => any;
private readonly _lastFocusedElement: HTMLElement | null;

private _isDisposed: boolean = false;
private _hoverPosition: HoverPosition;
Expand Down Expand Up @@ -88,6 +89,8 @@ export class HoverWidget extends Widget {
) {
super();

this._lastFocusedElement = <HTMLElement | null>document.activeElement;

this._linkHandler = options.linkHandler || (url => {
return openLinkFromMarkdown(this._openerService, url, isMarkdownString(options.content) ? options.content.isTrusted : undefined);
});
Expand Down Expand Up @@ -119,6 +122,7 @@ export class HoverWidget extends Widget {
// Hide hover on escape
this.onkeydown(this._hover.containerDomNode, e => {
if (e.equals(KeyCode.Escape)) {
this._lastFocusedElement?.focus();
this.dispose();
}
});
Expand Down

0 comments on commit 67271fc

Please sign in to comment.