@@ -17,6 +17,7 @@ import { addDisposableListener, EventType } from 'vs/base/browser/dom';
17
17
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
18
18
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent' ;
19
19
import { ResultKind } from 'vs/platform/keybinding/common/keybindingResolver' ;
20
+ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
20
21
21
22
export class HoverService implements IHoverService {
22
23
declare readonly _serviceBrand : undefined ;
@@ -31,23 +32,27 @@ export class HoverService implements IHoverService {
31
32
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
32
33
@IContextViewService private readonly _contextViewService : IContextViewService ,
33
34
@IContextMenuService contextMenuService : IContextMenuService ,
34
- @IKeybindingService private readonly _keybindingService : IKeybindingService
35
+ @IKeybindingService private readonly _keybindingService : IKeybindingService ,
36
+ @IAccessibilityService private readonly _accessibilityService : IAccessibilityService
35
37
) {
36
38
contextMenuService . onDidShowContextMenu ( ( ) => this . hideHover ( ) ) ;
37
39
}
38
40
39
- showHover ( options : IHoverOptions , focus ?: boolean ) : IHoverWidget | undefined {
41
+ showHover ( options : IHoverOptions , focus ?: boolean , skipLastFocusedUpdate ?: boolean ) : IHoverWidget | undefined {
40
42
if ( getHoverOptionsIdentity ( this . _currentHoverOptions ) === getHoverOptionsIdentity ( options ) ) {
41
43
return undefined ;
42
44
}
43
45
this . _currentHoverOptions = options ;
44
46
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
+ }
49
55
}
50
-
51
56
const hoverDisposables = new DisposableStore ( ) ;
52
57
const hover = this . _instantiationService . createInstance ( HoverWidget , options ) ;
53
58
hover . onDispose ( ( ) => {
@@ -114,7 +119,7 @@ export class HoverService implements IHoverService {
114
119
if ( ! this . _lastHoverOptions ) {
115
120
return ;
116
121
}
117
- this . showHover ( this . _lastHoverOptions , true ) ;
122
+ this . showHover ( this . _lastHoverOptions , true , true ) ;
118
123
}
119
124
120
125
private _keyDown ( e : KeyboardEvent , hover : HoverWidget , hideOnKeyDown : boolean ) {
0 commit comments