@@ -106,6 +106,9 @@ export class ModelEditorView extends AbstractWebview<
106106 this . databaseItem ,
107107 this . hideModeledMethods ,
108108 ) ;
109+ await this . markModelEditorAsActive ( ) ;
110+ } else {
111+ await this . updateModelEditorActiveContext ( ) ;
109112 }
110113 } ) ;
111114
@@ -129,6 +132,22 @@ export class ModelEditorView extends AbstractWebview<
129132 ) ;
130133 }
131134
135+ private async markModelEditorAsActive ( ) : Promise < void > {
136+ void this . app . commands . execute (
137+ "setContext" ,
138+ "codeql.modelEditorActive" ,
139+ true ,
140+ ) ;
141+ }
142+
143+ private async updateModelEditorActiveContext ( ) : Promise < void > {
144+ await this . app . commands . execute (
145+ "setContext" ,
146+ "codeql.modelEditorActive" ,
147+ this . isAModelEditorActive ( ) ,
148+ ) ;
149+ }
150+
132151 private isAModelEditorOpen ( ) : boolean {
133152 return window . tabGroups . all . some ( ( tabGroup ) =>
134153 tabGroup . tabs . some ( ( tab ) => {
@@ -140,6 +159,17 @@ export class ModelEditorView extends AbstractWebview<
140159 ) ;
141160 }
142161
162+ private isAModelEditorActive ( ) : boolean {
163+ return window . tabGroups . all . some ( ( tabGroup ) =>
164+ tabGroup . tabs . some ( ( tab ) => {
165+ const viewType : string | undefined = ( tab . input as any ) ?. viewType ;
166+ // The viewType has a prefix, such as "mainThreadWebview-", but if the
167+ // suffix matches that should be enough to identify the view.
168+ return viewType && viewType . endsWith ( "model-editor" ) && tab . isActive ;
169+ } ) ,
170+ ) ;
171+ }
172+
143173 protected async getPanelConfig ( ) : Promise < WebviewPanelConfig > {
144174 return {
145175 viewId : "model-editor" ,
0 commit comments