@@ -26,7 +26,9 @@ import { ManagedHoverWidget } from './updatableHoverWidget.js';
26
26
import { timeout , TimeoutTimer } from '../../../../base/common/async.js' ;
27
27
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js' ;
28
28
import { isNumber } from '../../../../base/common/types.js' ;
29
- import { KeyCode } from '../../../../base/common/keyCodes.js' ;
29
+ import { KeyChord , KeyCode , KeyMod } from '../../../../base/common/keyCodes.js' ;
30
+ import { KeybindingsRegistry , KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js' ;
31
+ import { EditorContextKeys } from '../../../common/editorContextKeys.js' ;
30
32
31
33
export class HoverService extends Disposable implements IHoverService {
32
34
declare readonly _serviceBrand : undefined ;
@@ -41,6 +43,9 @@ export class HoverService extends Disposable implements IHoverService {
41
43
42
44
private _lastFocusedElementBeforeOpen : HTMLElement | undefined ;
43
45
46
+ private readonly _delayedHovers = new Map < HTMLElement , { show : ( focus : boolean ) => void } > ( ) ;
47
+ private readonly _managedHovers = new Map < HTMLElement , IManagedHover > ( ) ;
48
+
44
49
constructor (
45
50
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
46
51
@IConfigurationService private readonly _configurationService : IConfigurationService ,
@@ -53,6 +58,14 @@ export class HoverService extends Disposable implements IHoverService {
53
58
54
59
this . _register ( contextMenuService . onDidShowContextMenu ( ( ) => this . hideHover ( ) ) ) ;
55
60
this . _contextViewHandler = this . _register ( new ContextViewHandler ( this . _layoutService ) ) ;
61
+
62
+ this . _register ( KeybindingsRegistry . registerCommandAndKeybindingRule ( {
63
+ id : 'workbench.action.showHover' ,
64
+ weight : KeybindingWeight . WorkbenchContrib - 1 ,
65
+ when : EditorContextKeys . editorTextFocus . negate ( ) ,
66
+ primary : KeyChord ( KeyMod . CtrlCmd | KeyCode . KeyK , KeyMod . CtrlCmd | KeyCode . KeyI ) ,
67
+ handler : ( ) => { this . _showAndFocusHoverForActiveElement ( ) ; } ,
68
+ } ) ) ;
56
69
}
57
70
58
71
showHover ( options : IHoverOptions , focus ?: boolean , skipLastFocusedUpdate ?: boolean , dontShow ?: boolean ) : IHoverWidget | undefined {
@@ -160,6 +173,10 @@ export class HoverService extends Disposable implements IHoverService {
160
173
}
161
174
} ) ) ;
162
175
}
176
+
177
+ this . _delayedHovers . set ( target , { show : ( focus : boolean ) => { this . showHover ( resolveHoverOptions ( ) , focus ) ; } } ) ;
178
+ store . add ( toDisposable ( ( ) => this . _delayedHovers . delete ( target ) ) ) ;
179
+
163
180
return store ;
164
181
}
165
182
@@ -301,6 +318,21 @@ export class HoverService extends Disposable implements IHoverService {
301
318
this . showHover ( this . _lastHoverOptions , true , true ) ;
302
319
}
303
320
321
+ private _showAndFocusHoverForActiveElement ( ) : void {
322
+ // TODO: if hover is visible, focus it to avoid flickering
323
+
324
+ let activeElement = getActiveElement ( ) as HTMLElement | null ;
325
+ while ( activeElement ) {
326
+ const hover = this . _delayedHovers . get ( activeElement ) ?? this . _managedHovers . get ( activeElement ) ;
327
+ if ( hover ) {
328
+ hover . show ( true ) ;
329
+ return ;
330
+ }
331
+
332
+ activeElement = activeElement . parentElement ;
333
+ }
334
+ }
335
+
304
336
private _keyDown ( e : KeyboardEvent , hover : HoverWidget , hideOnKeyDown : boolean ) {
305
337
if ( e . key === 'Alt' ) {
306
338
hover . isLocked = true ;
@@ -328,8 +360,6 @@ export class HoverService extends Disposable implements IHoverService {
328
360
}
329
361
}
330
362
331
- private readonly _managedHovers = new Map < HTMLElement , IManagedHover > ( ) ;
332
-
333
363
// TODO: Investigate performance of this function. There seems to be a lot of content created
334
364
// and thrown away on start up
335
365
setupManagedHover ( hoverDelegate : IHoverDelegate , targetElement : HTMLElement , content : IManagedHoverContentOrFactory , options ?: IManagedHoverOptions | undefined ) : IManagedHover {
0 commit comments