diff --git a/manifest.json b/manifest.json index 6ddb11d..7d3f68a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-folder-index", "name": "Folder Index", - "version": "1.0.22", + "version": "1.0.23", "minAppVersion": "1.1.16", "description": "This Plugin will automatically generate a TOC for the current Folder.", "author": "turulix", diff --git a/package-lock.json b/package-lock.json index 319cf70..3528d6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-sample-plugin", - "version": "1.0.21", + "version": "1.0.22", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-sample-plugin", - "version": "1.0.21", + "version": "1.0.22", "license": "MIT", "devDependencies": { "@types/node": "16.11.6", diff --git a/package.json b/package.json index d4aa5da..5c41846 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-sample-plugin", - "version": "1.0.22", + "version": "1.0.23", "description": "This is a sample plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/src/modules/FolderNoteModule.ts b/src/modules/FolderNoteModule.ts index cf3bc5d..d961ce2 100644 --- a/src/modules/FolderNoteModule.ts +++ b/src/modules/FolderNoteModule.ts @@ -102,7 +102,7 @@ export class FolderNoteModule { const file = this.app.vault.getAbstractFileByPath(path) if (file instanceof TFile) { - await this.app.workspace.getLeaf().openFile(file) + await this.app.workspace.getLeaf(false).openFile(file) } } @@ -166,15 +166,21 @@ export class FolderNoteModule { } private async onLayoutChange() { + const currentLeaf = this.app.workspace.getMostRecentLeaf() + if (currentLeaf == null) { + return; + } + const currentState = currentLeaf.getViewState(); + try { + // try { if (this.previousState == null) { - this.previousState = this.app.workspace.getLeaf().getViewState() + this.previousState = currentLeaf.getViewState(); } if (!this.plugin.settings.autoPreviewMode) { return; } - const currentState = this.app.workspace.getLeaf().getViewState() // We weren't in a markdown file before, so we don't care if (!(currentState.type == "markdown" && this.previousState.type == "markdown")) { @@ -184,7 +190,6 @@ export class FolderNoteModule { // We didn't change files, so we don't care if (currentState.state.file == this.previousState.state.file) return; - const currentFile = this.app.vault.getAbstractFileByPath(currentState.state.file) as TFile // We did not open an index file, so we need to check if the previous mode was set by this plugin @@ -192,23 +197,21 @@ export class FolderNoteModule { if (this.viewModeByPlugin) { this.viewModeByPlugin = false currentState.state.mode = "source" - await this.app.workspace.getLeaf().setViewState(currentState) + await currentLeaf.setViewState(currentState) } return; } - - // We are already inside the Preview Mode. + // // We are already inside the Preview Mode. if (this.previousState.state.mode == "preview") { return; } else { currentState.state.mode = "preview" this.viewModeByPlugin = true - await this.app.workspace.getLeaf().setViewState(currentState) + await currentLeaf.setViewState(currentState) } } finally { - const currentState = this.app.workspace.getLeaf().getViewState(); if (currentState.type == "markdown") - this.previousState = currentState; + this.previousState = currentLeaf.getViewState(); } } diff --git a/versions.json b/versions.json index 1fd2458..55e255c 100644 --- a/versions.json +++ b/versions.json @@ -13,5 +13,6 @@ "1.0.19": "1.1.16", "1.0.20": "1.1.16", "1.0.21": "1.1.16", - "1.0.22": "1.1.16" + "1.0.22": "1.1.16", + "1.0.23": "1.1.16" } \ No newline at end of file