Skip to content

Commit 868ffd7

Browse files
authored
Hide modeling panel when modeling editor is active (#2851)
1 parent 3934ba7 commit 868ffd7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

extensions/ql-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@
17841784
"type": "webview",
17851785
"id": "codeQLMethodModeling",
17861786
"name": "CodeQL Method Modeling",
1787-
"when": "config.codeQL.canary && config.codeQL.model.methodModelingView && codeql.modelEditorOpen"
1787+
"when": "config.codeQL.canary && config.codeQL.model.methodModelingView && codeql.modelEditorOpen && !codeql.modelEditorActive"
17881788
}
17891789
]
17901790
},

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)