4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ;
7
- import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
7
+ import { Disposable , DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
8
8
import { IMarkdownString } from 'vs/base/common/htmlContent' ;
9
9
import { HoverPosition } from 'vs/base/browser/ui/hover/hoverWidget' ;
10
10
import { IHoverDelegate , IHoverDelegateOptions , IHoverWidget } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate' ;
11
11
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
12
+ import { addStandardDisposableListener } from 'vs/base/browser/dom' ;
13
+ import { KeyCode } from 'vs/base/common/keyCodes' ;
12
14
13
15
export const IHoverService = createDecorator < IHoverService > ( 'hoverService' ) ;
14
16
@@ -245,6 +247,8 @@ export class WorkbenchHoverDelegate extends Disposable implements IHoverDelegate
245
247
return this . _delay ;
246
248
}
247
249
250
+ private hoverDisposables = this . _register ( new DisposableStore ( ) ) ;
251
+
248
252
constructor (
249
253
public readonly placement : 'mouse' | 'element' ,
250
254
private readonly instantHover : boolean ,
@@ -264,6 +268,18 @@ export class WorkbenchHoverDelegate extends Disposable implements IHoverDelegate
264
268
265
269
showHover ( options : IHoverDelegateOptions , focus ?: boolean ) : IHoverWidget | undefined {
266
270
const overrideOptions = typeof this . overrideOptions === 'function' ? this . overrideOptions ( options , focus ) : this . overrideOptions ;
271
+
272
+ // close hover on escape
273
+ this . hoverDisposables . clear ( ) ;
274
+ const targets = options . target instanceof HTMLElement ? [ options . target ] : options . target . targetElements ;
275
+ for ( const target of targets ) {
276
+ this . hoverDisposables . add ( addStandardDisposableListener ( target , 'keydown' , ( e ) => {
277
+ if ( e . equals ( KeyCode . Escape ) ) {
278
+ this . hoverService . hideHover ( ) ;
279
+ }
280
+ } ) ) ;
281
+ }
282
+
267
283
return this . hoverService . showHover ( {
268
284
...options ,
269
285
persistence : {
@@ -278,6 +294,7 @@ export class WorkbenchHoverDelegate extends Disposable implements IHoverDelegate
278
294
}
279
295
280
296
onDidHideHover ( ) : void {
297
+ this . hoverDisposables . clear ( ) ;
281
298
if ( this . instantHover ) {
282
299
this . lastHoverHideTime = Date . now ( ) ;
283
300
}
0 commit comments