feat(main): ribbon opens the panel as a tab, tab and sidedock leaves reused separately
This commit is contained in:
+8
-2
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user