# HG changeset patch # User Ludovic Chabant # Date 1647656748 25200 # Node ID f7e0926c25000878138cf6d8470192ff80143644 # Parent 815b93d13e0fabf5700970fa031da4c388362912 Don't restore state on a file that's already open in another pane. diff -r 815b93d13e0f -r f7e0926c2500 src/main.ts --- 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;