@@ -20,7 +20,7 @@ import { CodeActionKind, CodeActionTrigger, CodeActionTriggerSource } from 'vs/e
2020import 'vs/editor/contrib/symbolIcons/browser/symbolIcons' ; // The codicon symbol colors are defined here and must be loaded to get colors
2121import { localize } from 'vs/nls' ;
2222import { ICommandService } from 'vs/platform/commands/common/commands' ;
23- import { IContextKey , IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
23+ import { IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
2424import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
2525import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
2626import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
@@ -369,40 +369,44 @@ export class CodeActionWidget extends Disposable {
369369 readonly container : HTMLElement | undefined ;
370370 readonly codeActions : CodeActionSet ;
371371 readonly delegate : CodeActionWidgetDelegate ;
372+ readonly contextKeyService : IContextKeyService ;
372373 } ;
373374
374- private readonly _ctxMenuWidgetVisible : IContextKey < boolean > ;
375-
376375 constructor (
377376 @ICommandService private readonly _commandService : ICommandService ,
378- @IContextKeyService private readonly _contextKeyService : IContextKeyService ,
379377 @IContextViewService private readonly _contextViewService : IContextViewService ,
380378 @IKeybindingService private readonly _keybindingService : IKeybindingService ,
381379 @ITelemetryService private readonly _telemetryService : ITelemetryService ,
382380 ) {
383381 super ( ) ;
384-
385- this . _ctxMenuWidgetVisible = Context . Visible . bindTo ( this . _contextKeyService ) ;
386382 }
387383
388384 get isVisible ( ) : boolean {
389385 return ! ! this . currentShowingContext ;
390386 }
391387
392- public async show ( trigger : CodeActionTrigger , codeActions : CodeActionSet , anchor : IAnchor , container : HTMLElement | undefined , options : CodeActionShowOptions , delegate : CodeActionWidgetDelegate ) : Promise < void > {
388+ public async show ( trigger : CodeActionTrigger , codeActions : CodeActionSet , anchor : IAnchor , container : HTMLElement | undefined , options : CodeActionShowOptions , delegate : CodeActionWidgetDelegate , contextKeyService : IContextKeyService ) : Promise < void > {
393389 this . currentShowingContext = undefined ;
390+ const visibleContext = Context . Visible . bindTo ( contextKeyService ) ;
394391
395392 const actionsToShow = options . includeDisabledActions && ( showDisabled || codeActions . validActions . length === 0 ) ? codeActions . allActions : codeActions . validActions ;
396393 if ( ! actionsToShow . length ) {
394+ visibleContext . reset ( ) ;
397395 return ;
398396 }
399397
400- this . currentShowingContext = { trigger, codeActions, anchor, container, delegate, options } ;
398+ this . currentShowingContext = { trigger, codeActions, anchor, container, delegate, options, contextKeyService } ;
401399
402400 this . _contextViewService . showContextView ( {
403401 getAnchor : ( ) => anchor ,
404- render : ( container : HTMLElement ) => this . renderWidget ( container , trigger , codeActions , options , actionsToShow , delegate ) ,
405- onHide : ( didCancel : boolean ) => this . onWidgetClosed ( trigger , options , codeActions , didCancel , delegate ) ,
402+ render : ( container : HTMLElement ) => {
403+ visibleContext . set ( true ) ;
404+ return this . renderWidget ( container , trigger , codeActions , options , actionsToShow , delegate ) ;
405+ } ,
406+ onHide : ( didCancel : boolean ) => {
407+ visibleContext . reset ( ) ;
408+ return this . onWidgetClosed ( trigger , options , codeActions , didCancel , delegate ) ;
409+ } ,
406410 } , container , false ) ;
407411 }
408412
@@ -487,8 +491,6 @@ export class CodeActionWidget extends Disposable {
487491 const focusTracker = renderDisposables . add ( dom . trackFocus ( element ) ) ;
488492 renderDisposables . add ( focusTracker . onDidBlur ( ( ) => this . hide ( ) ) ) ;
489493
490- this . _ctxMenuWidgetVisible . set ( true ) ;
491-
492494 return renderDisposables ;
493495 }
494496
@@ -503,7 +505,7 @@ export class CodeActionWidget extends Disposable {
503505 showDisabled = newShowDisabled ;
504506
505507 if ( previousCtx ) {
506- this . show ( previousCtx . trigger , previousCtx . codeActions , previousCtx . anchor , previousCtx . container , previousCtx . options , previousCtx . delegate ) ;
508+ this . show ( previousCtx . trigger , previousCtx . codeActions , previousCtx . anchor , previousCtx . container , previousCtx . options , previousCtx . delegate , previousCtx . contextKeyService ) ;
507509 }
508510 }
509511
@@ -529,7 +531,7 @@ export class CodeActionWidget extends Disposable {
529531 } ) ;
530532
531533 this . currentShowingContext = undefined ;
532- this . _ctxMenuWidgetVisible . reset ( ) ;
534+
533535 delegate . onHide ( cancelled ) ;
534536 }
535537
0 commit comments