From b00b6b8d407371450bf4ab0f88cf1fd68f36855f Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Mon, 16 Oct 2023 11:59:31 +0200 Subject: [PATCH] fix: do not close existing leafs, reuse instead fix: open the main view in a new tab fixes #36 --- src/main.ts | 16 +++++++-------- tsconfig.json | 55 ++++++++++++++++++++++++++------------------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/main.ts b/src/main.ts index ff27110a..525b54b5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -97,11 +97,12 @@ export default class ModalFormPlugin extends Plugin { onunload() { } async activateView(viewType: ViewType, state?: FormDefinition) { - this.app.workspace.detachLeavesOfType(viewType); - - let leaf: WorkspaceLeaf; - if (Platform.isMobile || this.settings?.editorPosition === "mainView") { - leaf = this.app.workspace.getLeaf(false) + const { workspace } = this.app; + let leaf = workspace.getLeavesOfType(viewType)[0]; + if (leaf) { + console.info('found leaf, no reason to create a new one') + } else if (Platform.isMobile || this.settings?.editorPosition === "mainView") { + leaf = this.app.workspace.getLeaf('tab') } else if (this.settings?.editorPosition === "right") { leaf = this.app.workspace.getRightLeaf(false); } else if (this.settings?.editorPosition === "left") { @@ -117,11 +118,10 @@ export default class ModalFormPlugin extends Plugin { active: true, state, }); - const leave = this.app.workspace.getLeavesOfType(viewType)[0] this.app.workspace.revealLeaf( - leave + leaf ); - return leave; + return leaf; } async getSettings(): Promise { diff --git a/tsconfig.json b/tsconfig.json index a8225aba..8f457158 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,29 +1,30 @@ { - "extends": "@tsconfig/svelte/tsconfig.json", - "compilerOptions": { - "baseUrl": ".", - "inlineSources": true, - "module": "ESNext", - "target": "ES6", - "allowJs": true, - "noImplicitAny": true, - "moduleResolution": "node", - "importHelpers": true, - "isolatedModules": true, - "strictNullChecks": true, - "strict": true, - "types": [ - "svelte", - "node" - ], - "lib": [ - "DOM", - "ES5", - "ES6", - "ES7" - ] - }, - "include": [ - "**/*.ts" - ] + "extends": "@tsconfig/svelte/tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "inlineSources": true, + "module": "ESNext", + "target": "ES6", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "importHelpers": true, + "isolatedModules": true, + "strictNullChecks": true, + "strict": true, + "noUncheckedIndexedAccess": true, + "types": [ + "svelte", + "node" + ], + "lib": [ + "DOM", + "ES5", + "ES6", + "ES7" + ] + }, + "include": [ + "**/*.ts" + ] }