Skip to content

Commit

Permalink
fix: do not close existing leafs, reuse instead
Browse files Browse the repository at this point in the history
fix: open the main view in a new tab

fixes #36
  • Loading branch information
danielo515 committed Oct 16, 2023
1 parent 03bf4ea commit b00b6b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
16 changes: 8 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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<ModalFormSettings> {
Expand Down
55 changes: 28 additions & 27 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit b00b6b8

Please sign in to comment.