@@ -17,6 +17,7 @@ import { addDisposableListener, EventType } from 'vs/base/browser/dom';
1717import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
1818import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent' ;
1919import { ResultKind } from 'vs/platform/keybinding/common/keybindingResolver' ;
20+ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
2021
2122export class HoverService implements IHoverService {
2223 declare readonly _serviceBrand : undefined ;
@@ -31,23 +32,27 @@ 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 : Readonly < IHoverOptions > , focus ?: boolean ) : IHoverWidget | undefined {
41+ showHover ( options : Readonly < 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+ const trapFocus = options . trapFocus || this . _accessibilityService . isScreenReaderOptimized ( ) ;
48+ // HACK, remove this check when #189076 is fixed
49+ if ( ! skipLastFocusedUpdate ) {
50+ if ( trapFocus && document . activeElement ) {
51+ this . _lastFocusedElementBeforeOpen = document . activeElement as HTMLElement ;
52+ } else {
53+ this . _lastFocusedElementBeforeOpen = undefined ;
54+ }
4955 }
50-
5156 const hoverDisposables = new DisposableStore ( ) ;
5257 const hover = this . _instantiationService . createInstance ( HoverWidget , options ) ;
5358 hover . onDispose ( ( ) => {
@@ -114,7 +119,7 @@ export class HoverService implements IHoverService {
114119 if ( ! this . _lastHoverOptions ) {
115120 return ;
116121 }
117- this . showHover ( this . _lastHoverOptions , true ) ;
122+ this . showHover ( this . _lastHoverOptions , true , true ) ;
118123 }
119124
120125 private _keyDown ( e : KeyboardEvent , hover : HoverWidget , hideOnKeyDown : boolean ) {
0 commit comments