Mercurial > obsidian-remember-file-state
changeset 22:f7e0926c2500
Don't restore state on a file that's already open in another pane.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 18 Mar 2022 19:25:48 -0700 |
parents | 815b93d13e0f |
children | ba74a7d3709c |
files | src/main.ts |
diffstat | 1 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main.ts Fri Mar 18 19:25:18 2022 -0700 +++ b/src/main.ts Fri Mar 18 19:25:48 2022 -0700 @@ -202,7 +202,11 @@ if (activeView) { this.registerOnUnloadFile(activeView); - if (!this._suppressNextFileOpen) { + // Don't restore the file state if: + // - We are suppressing it explicitly (such as if the file was + // opened via clicking a hyperlink) + // - The file is already currently open in another pane + if (!this._suppressNextFileOpen && !this.isFileMultiplyOpen(openedFile)) { this.restoreFileState(openedFile, activeView); } } @@ -255,6 +259,18 @@ cm6editor.cm.dispatch(transaction); } } + + private readonly isFileMultiplyOpen = function(file: TFile) { + var numFound: number = 0; + this.app.workspace.getLeavesOfType("markdown").forEach( + (leaf: WorkspaceLeaf) => { + const filePath = (leaf.view as MarkdownView).file.path; + if (filePath == file.path) { + ++numFound; + } + }); + return numFound >= 2; + } private readonly forgetExcessFiles = function() { const keepMax = this.settings.rememberMaxFiles;