From 52c100544081eec6f48141a0e9de5c54645203b5 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 1 Jun 2022 15:04:53 +0200 Subject: [PATCH] allow holding control to open a center frame in a new split Closes #33 --- src/main.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4636d07..d6c86bd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,11 +26,12 @@ export default class CustomFramesPlugin extends Plugin { this.addCommand({ id: `open-${name}`, name: `Open ${frame.displayName}`, - callback: () => this.openLeaf(name, frame.openInCenter), + callback: () => this.openLeaf(name, frame.openInCenter, false), }); if (frame.addRibbonIcon) - this.addRibbonIcon(getIcon(frame), `Open ${frame.displayName}`, () => this.openLeaf(name, frame.openInCenter)); + this.addRibbonIcon(getIcon(frame), `Open ${frame.displayName}`, + e => this.openLeaf(name, frame.openInCenter, Platform.isMacOS ? e.metaKey : e.ctrlKey)); } catch { console.error(`Couldn't register frame ${name}, is there already one with the same name?`); } @@ -75,10 +76,11 @@ export default class CustomFramesPlugin extends Plugin { await this.saveData(this.settings); } - private async openLeaf(name: string, center: boolean): Promise { + private async openLeaf(name: string, center: boolean, split: boolean): Promise { if (center) { this.app.workspace.detachLeavesOfType(name); - await this.app.workspace.getUnpinnedLeaf().setViewState({ type: name }); + let leaf = split ? this.app.workspace.splitActiveLeaf() : this.app.workspace.getUnpinnedLeaf(); + await leaf.setViewState({ type: name }); } else { if (!this.app.workspace.getLeavesOfType(name).length)