Skip to content

Commit 9123c57

Browse files
committed
1 parent 34442b8 commit 9123c57

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/vs/workbench/services/hover/browser/hoverService.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { addDisposableListener, EventType } from 'vs/base/browser/dom';
1717
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1818
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
1919
import { ResultKind } from 'vs/platform/keybinding/common/keybindingResolver';
20+
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
2021

2122
export class HoverService implements IHoverService {
2223
declare readonly _serviceBrand: undefined;
@@ -31,23 +32,26 @@ export class HoverService implements IHoverService {
3132
@IInstantiationService private readonly _instantiationService: IInstantiationService,
3233
@IContextViewService private readonly _contextViewService: IContextViewService,
3334
@IContextMenuService contextMenuService: IContextMenuService,
34-
@IKeybindingService private readonly _keybindingService: IKeybindingService
35+
@IKeybindingService private readonly _keybindingService: IKeybindingService,
36+
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService
3537
) {
3638
contextMenuService.onDidShowContextMenu(() => this.hideHover());
3739
}
3840

39-
showHover(options: IHoverOptions, focus?: boolean): IHoverWidget | undefined {
41+
showHover(options: IHoverOptions, focus?: boolean, skipLastFocusedUpdate?: boolean): IHoverWidget | undefined {
4042
if (getHoverOptionsIdentity(this._currentHoverOptions) === getHoverOptionsIdentity(options)) {
4143
return undefined;
4244
}
4345
this._currentHoverOptions = options;
4446
this._lastHoverOptions = options;
45-
if (options.trapFocus && document.activeElement) {
46-
this._lastFocusedElementBeforeOpen = document.activeElement as HTMLElement;
47-
} else {
48-
this._lastFocusedElementBeforeOpen = undefined;
47+
options.trapFocus = options.trapFocus || this._accessibilityService.isScreenReaderOptimized();
48+
if (!skipLastFocusedUpdate) {
49+
if (options.trapFocus && document.activeElement) {
50+
this._lastFocusedElementBeforeOpen = document.activeElement as HTMLElement;
51+
} else {
52+
this._lastFocusedElementBeforeOpen = undefined;
53+
}
4954
}
50-
5155
const hoverDisposables = new DisposableStore();
5256
const hover = this._instantiationService.createInstance(HoverWidget, options);
5357
hover.onDispose(() => {
@@ -114,7 +118,7 @@ export class HoverService implements IHoverService {
114118
if (!this._lastHoverOptions) {
115119
return;
116120
}
117-
this.showHover(this._lastHoverOptions, true);
121+
this.showHover(this._lastHoverOptions, true, true);
118122
}
119123

120124
private _keyDown(e: KeyboardEvent, hover: HoverWidget, hideOnKeyDown: boolean) {

0 commit comments

Comments
 (0)