feat(main): ribbon opens the panel as a tab, tab and sidedock leaves reused separately

This commit is contained in:
hh
2026-08-29 19:08:50 +02:00
parent 04400c5076
commit 8e74439b4d
2 changed files with 10 additions and 4 deletions
+8 -2
View File
@@ -163,7 +163,7 @@ export default class BeaverPlugin extends Plugin {
this.addSettingTab(new BeaverSettingsTab(this.app, this));
this.registerView(VIEW_TYPE_PANEL, (leaf) => new PanelView(leaf, this));
this.addRibbonIcon("bot", "Beaver", () => {
this.openPanel("side").catch(() => undefined);
this.openPanel("tab").catch(() => undefined);
});
this.addCommand({
@@ -279,10 +279,16 @@ export default class BeaverPlugin extends Plugin {
}
// Reveal a panel (creating one on first use) and, given an id, show it.
// A tab and a sidedock column can coexist; each placement reuses its own.
async openPanel(placement: "side" | "tab", id?: string): Promise<void> {
const { workspace } = this.app;
const inTabs = (candidate: WorkspaceLeaf) =>
candidate.getRoot() === workspace.rootSplit;
let leaf: WorkspaceLeaf | null =
workspace.getLeavesOfType(VIEW_TYPE_PANEL)[0] ?? null;
workspace
.getLeavesOfType(VIEW_TYPE_PANEL)
.find((candidate) => inTabs(candidate) === (placement === "tab")) ??
null;
if (!leaf) {
leaf =
placement === "tab"