@@ -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,26 @@ 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
+ 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
+ }
49
54
}
50
-
51
55
const hoverDisposables = new DisposableStore ( ) ;
52
56
const hover = this . _instantiationService . createInstance ( HoverWidget , options ) ;
53
57
hover . onDispose ( ( ) => {
@@ -114,7 +118,7 @@ export class HoverService implements IHoverService {
114
118
if ( ! this . _lastHoverOptions ) {
115
119
return ;
116
120
}
117
- this . showHover ( this . _lastHoverOptions , true ) ;
121
+ this . showHover ( this . _lastHoverOptions , true , true ) ;
118
122
}
119
123
120
124
private _keyDown ( e : KeyboardEvent , hover : HoverWidget , hideOnKeyDown : boolean ) {
0 commit comments