allow holding control to open a center frame in a new split

Closes #33
This commit is contained in:
Ell 2022-06-01 15:04:53 +02:00
parent 5a0597d930
commit 52c1005440

View file

@ -26,11 +26,12 @@ export default class CustomFramesPlugin extends Plugin {
this.addCommand({ this.addCommand({
id: `open-${name}`, id: `open-${name}`,
name: `Open ${frame.displayName}`, name: `Open ${frame.displayName}`,
callback: () => this.openLeaf(name, frame.openInCenter), callback: () => this.openLeaf(name, frame.openInCenter, false),
}); });
if (frame.addRibbonIcon) 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 { } catch {
console.error(`Couldn't register frame ${name}, is there already one with the same name?`); 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); await this.saveData(this.settings);
} }
private async openLeaf(name: string, center: boolean): Promise<void> { private async openLeaf(name: string, center: boolean, split: boolean): Promise<void> {
if (center) { if (center) {
this.app.workspace.detachLeavesOfType(name); 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 { else {
if (!this.app.workspace.getLeavesOfType(name).length) if (!this.app.workspace.getLeavesOfType(name).length)