Hide modeling panel when modeling editor is active (#2851)

This commit is contained in:
Charis Kyriakou
2023-09-25 10:39:43 +01:00
committed by GitHub
parent 3934ba7e69
commit 868ffd79a5
2 changed files with 31 additions and 1 deletions

View File

@@ -1784,7 +1784,7 @@
"type": "webview",
"id": "codeQLMethodModeling",
"name": "CodeQL Method Modeling",
"when": "config.codeQL.canary && config.codeQL.model.methodModelingView && codeql.modelEditorOpen"
"when": "config.codeQL.canary && config.codeQL.model.methodModelingView && codeql.modelEditorOpen && !codeql.modelEditorActive"
}
]
},

View File

@@ -106,6 +106,9 @@ export class ModelEditorView extends AbstractWebview<
this.databaseItem,
this.hideModeledMethods,
);
await this.markModelEditorAsActive();
} else {
await this.updateModelEditorActiveContext();
}
});
@@ -129,6 +132,22 @@ export class ModelEditorView extends AbstractWebview<
);
}
private async markModelEditorAsActive(): Promise<void> {
void this.app.commands.execute(
"setContext",
"codeql.modelEditorActive",
true,
);
}
private async updateModelEditorActiveContext(): Promise<void> {
await this.app.commands.execute(
"setContext",
"codeql.modelEditorActive",
this.isAModelEditorActive(),
);
}
private isAModelEditorOpen(): boolean {
return window.tabGroups.all.some((tabGroup) =>
tabGroup.tabs.some((tab) => {
@@ -140,6 +159,17 @@ export class ModelEditorView extends AbstractWebview<
);
}
private isAModelEditorActive(): boolean {
return window.tabGroups.all.some((tabGroup) =>
tabGroup.tabs.some((tab) => {
const viewType: string | undefined = (tab.input as any)?.viewType;
// The viewType has a prefix, such as "mainThreadWebview-", but if the
// suffix matches that should be enough to identify the view.
return viewType && viewType.endsWith("model-editor") && tab.isActive;
}),
);
}
protected async getPanelConfig(): Promise<WebviewPanelConfig> {
return {
viewId: "model-editor",