diff --git a/src/main.ts b/src/main.ts index 50eca04..ef66e12 100644 --- a/src/main.ts +++ b/src/main.ts @@ -46,16 +46,15 @@ export default class VaultExplorerPlugin extends Plugin { ); this.addRibbonIcon("compass", "Open vault explorer", async () => { - const leaves = this.app.workspace.getLeavesOfType(VAULT_EXPLORER_VIEW); - if (leaves.length !== 0) { - const leaf = leaves[0]; - this.app.workspace.revealLeaf(leaf); - } else { - this.app.workspace.getLeaf().setViewState({ - type: VAULT_EXPLORER_VIEW, - active: true, - }); - } + this.openVaultExplorerView(); + }); + + this.addCommand({ + id: "open", + name: "Open vault explorer view", + callback: async () => { + this.openVaultExplorerView(); + }, }); this.registerEvents(); @@ -276,4 +275,17 @@ export default class VaultExplorerPlugin extends Plugin { Logger.debug({ fileName: "main.ts", functionName: "saveSettings", message: "saving settings" }, this.settings); await this.saveData(this.settings); } + + private openVaultExplorerView() { + const leaves = this.app.workspace.getLeavesOfType(VAULT_EXPLORER_VIEW); + if (leaves.length !== 0) { + const leaf = leaves[0]; + this.app.workspace.revealLeaf(leaf); + } else { + this.app.workspace.getLeaf().setViewState({ + type: VAULT_EXPLORER_VIEW, + active: true, + }); + } + } }