@@ -70,42 +70,44 @@ export class MonacoEditorContentMenuContribution implements FrontendApplicationC
7070 ) ;
7171 return ObservableUtils . autorunWithDisposables ( ( { toDispose } ) => {
7272 const menuNodes = menuNodesObservable . get ( ) ;
73- const firstMatchObservable = ObservableFromEvent . create ( contextKeyService . onDidChangeContext , ( ) => this . withContext ( context ,
74- ( ) => menuNodes . find ( menuNode => menuNode . isVisible ( EDITOR_CONTENT_MENU , this . contextKeyService , undefined , editorWidget ) )
75- ) ) ;
76- // eslint-disable-next-line @typescript-eslint/no-shadow
77- toDispose . push ( ObservableUtils . autorunWithDisposables ( ( { toDispose } ) => {
78- const firstMatch = firstMatchObservable . get ( ) ;
79- if ( firstMatch ) {
80- const button = new MonacoEditorOverlayButton ( editor , firstMatch . label ) ;
81- toDispose . push ( button ) ;
82- toDispose . push ( button . onClick ( ( ) =>
83- this . withContext ( context , ( ) => firstMatch . run ( EDITOR_CONTENT_MENU , editorWidget ) )
84- ) ) ;
73+ if ( menuNodes ) {
74+ const firstMatchObservable = ObservableFromEvent . create ( contextKeyService . onDidChangeContext , ( ) => this . withContext ( context ,
75+ ( ) => menuNodes . find ( menuNode => menuNode . isVisible ( EDITOR_CONTENT_MENU , this . contextKeyService , undefined , editorWidget ) )
76+ ) ) ;
77+ // eslint-disable-next-line @typescript-eslint/no-shadow
78+ toDispose . push ( ObservableUtils . autorunWithDisposables ( ( { toDispose } ) => {
79+ const firstMatch = firstMatchObservable . get ( ) ;
80+ if ( firstMatch ) {
81+ const button = new MonacoEditorOverlayButton ( editor , firstMatch . label ) ;
82+ toDispose . push ( button ) ;
83+ toDispose . push ( button . onClick ( ( ) =>
84+ this . withContext ( context , ( ) => firstMatch . run ( EDITOR_CONTENT_MENU , editorWidget ) )
85+ ) ) ;
8586
86- const handlersObservable = ObservableFromEvent . create ( this . commands . onCommandsChanged ,
87- ( ) => this . commands . getAllHandlers ( firstMatch . id ) ,
88- { isEqual : ( a , b ) => ArrayUtils . equals ( a , b ) }
89- ) ;
90- // eslint-disable-next-line @typescript-eslint/no-shadow
91- toDispose . push ( ObservableUtils . autorunWithDisposables ( ( { toDispose } ) => {
92- this . withContext ( context , ( ) => {
93- button . enabled = firstMatch . isEnabled ( EDITOR_CONTENT_MENU , editorWidget ) ;
94- const handlers = handlersObservable . get ( ) ;
95- for ( const handler of handlers ) {
96- const { onDidChangeEnabled } = handler ;
97- if ( onDidChangeEnabled ) {
98- // for handlers with declarative enablement such as those originating from `PluginContributionHandler.registerCommand`,
99- // the onDidChangeEnabled event is context-dependent, so we need to ensure the subscription is made within `withContext`
100- toDispose . push ( onDidChangeEnabled ( ( ) => this . withContext ( context , ( ) =>
101- button . enabled = firstMatch . isEnabled ( EDITOR_CONTENT_MENU , editorWidget )
102- ) ) ) ;
87+ const handlersObservable = ObservableFromEvent . create ( this . commands . onCommandsChanged ,
88+ ( ) => this . commands . getAllHandlers ( firstMatch . id ) ,
89+ { isEqual : ( a , b ) => ArrayUtils . equals ( a , b ) }
90+ ) ;
91+ // eslint-disable-next-line @typescript-eslint/no-shadow
92+ toDispose . push ( ObservableUtils . autorunWithDisposables ( ( { toDispose } ) => {
93+ this . withContext ( context , ( ) => {
94+ button . enabled = firstMatch . isEnabled ( EDITOR_CONTENT_MENU , editorWidget ) ;
95+ const handlers = handlersObservable . get ( ) ;
96+ for ( const handler of handlers ) {
97+ const { onDidChangeEnabled } = handler ;
98+ if ( onDidChangeEnabled ) {
99+ // for handlers with declarative enablement such as those originating from `PluginContributionHandler.registerCommand`,
100+ // the onDidChangeEnabled event is context-dependent, so we need to ensure the subscription is made within `withContext`
101+ toDispose . push ( onDidChangeEnabled ( ( ) => this . withContext ( context , ( ) =>
102+ button . enabled = firstMatch . isEnabled ( EDITOR_CONTENT_MENU , editorWidget )
103+ ) ) ) ;
104+ }
103105 }
104- }
105- } ) ;
106- } ) ) ;
107- }
108- } ) ) ;
106+ } ) ;
107+ } ) ) ;
108+ }
109+ } ) ) ;
110+ }
109111 } ) ;
110112 }
111113
0 commit comments