Mercurial > obsidian-remember-file-state
comparison src/main.ts @ 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 |
comparison
equal
deleted
inserted
replaced
21:815b93d13e0f | 22:f7e0926c2500 |
---|---|
200 if (openedFile) { | 200 if (openedFile) { |
201 var activeView: MarkdownView = this.app.workspace.getActiveViewOfType(MarkdownView); | 201 var activeView: MarkdownView = this.app.workspace.getActiveViewOfType(MarkdownView); |
202 if (activeView) { | 202 if (activeView) { |
203 this.registerOnUnloadFile(activeView); | 203 this.registerOnUnloadFile(activeView); |
204 | 204 |
205 if (!this._suppressNextFileOpen) { | 205 // Don't restore the file state if: |
206 // - We are suppressing it explicitly (such as if the file was | |
207 // opened via clicking a hyperlink) | |
208 // - The file is already currently open in another pane | |
209 if (!this._suppressNextFileOpen && !this.isFileMultiplyOpen(openedFile)) { | |
206 this.restoreFileState(openedFile, activeView); | 210 this.restoreFileState(openedFile, activeView); |
207 } | 211 } |
208 } | 212 } |
209 // else: the file isn't handled by a markdown editor. | 213 // else: the file isn't handled by a markdown editor. |
210 | 214 |
253 selection: EditorSelection.fromJSON(stateData.selection)}) | 257 selection: EditorSelection.fromJSON(stateData.selection)}) |
254 | 258 |
255 cm6editor.cm.dispatch(transaction); | 259 cm6editor.cm.dispatch(transaction); |
256 } | 260 } |
257 } | 261 } |
262 | |
263 private readonly isFileMultiplyOpen = function(file: TFile) { | |
264 var numFound: number = 0; | |
265 this.app.workspace.getLeavesOfType("markdown").forEach( | |
266 (leaf: WorkspaceLeaf) => { | |
267 const filePath = (leaf.view as MarkdownView).file.path; | |
268 if (filePath == file.path) { | |
269 ++numFound; | |
270 } | |
271 }); | |
272 return numFound >= 2; | |
273 } | |
258 | 274 |
259 private readonly forgetExcessFiles = function() { | 275 private readonly forgetExcessFiles = function() { |
260 const keepMax = this.settings.rememberMaxFiles; | 276 const keepMax = this.settings.rememberMaxFiles; |
261 if (keepMax <= 0) { | 277 if (keepMax <= 0) { |
262 return; | 278 return; |