From bbf1cd22fb3ec441fdd418f2346b2c7a6a8431d5 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 22 Mar 2022 13:22:58 +0100 Subject: [PATCH] also reveal the leaf when using the open command --- README.md | 2 ++ main.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e38265d..946f2d9 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,6 @@ An Obsidian plugin that allows adding iframes with custom styling as editor tabs ![A screenshot of the Obsidian Custom Frames plugin in action](screenshot.png) +To use this plugin, simply go into its settings and add a new frame, either from a preset shipped with the plugin, or a custom one that you can edit yourself. Each frame's tab can be opened using the 'Custom Frames: Open' command. + Note that this plugin only works on Desktop right now. \ No newline at end of file diff --git a/main.ts b/main.ts index 7866646..dfd39ff 100644 --- a/main.ts +++ b/main.ts @@ -47,13 +47,7 @@ export default class CustomFramesPlugin extends Plugin { this.addCommand({ id: `open-${name}`, name: `Open ${frame.displayName}`, - checkCallback: (checking: boolean) => { - if (this.app.workspace.getLeavesOfType(name).length) - return false; - if (!checking) - this.app.workspace.getRightLeaf(false).setViewState({ type: name }); - return true; - }, + callback: () => this.openLeaf(name), }); } catch { console.error(`Couldn't register frame ${name}, is there already one with the same name?`); @@ -70,6 +64,12 @@ export default class CustomFramesPlugin extends Plugin { async saveSettings() { await this.saveData(this.settings); } + + private async openLeaf(name: string): Promise { + if (!this.app.workspace.getLeavesOfType(name).length) + await this.app.workspace.getRightLeaf(false).setViewState({ type: name }); + this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(name)[0]); + } } class CustomFrameView extends ItemView {