mirror of
https://github.com/Ellpeck/ObsidianCustomFrames.git
synced 2024-11-14 14:59:08 +01:00
also reveal the leaf when using the open command
This commit is contained in:
parent
51e09944db
commit
bbf1cd22fb
2 changed files with 9 additions and 7 deletions
|
@ -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.
|
14
main.ts
14
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<void> {
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue