comparison src/main.ts @ 7:b1cb0474bb18

Fix possible crash when an opened file isn't a markdown file
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 14 Feb 2022 13:00:06 -0800
parents 114d7e6d2633
children ec6c48a07b03
comparison
equal deleted inserted replaced
6:114d7e6d2633 7:b1cb0474bb18
166 ): Promise<void> => { 166 ): Promise<void> => {
167 // If `openedFile` is null, it's because the last pane was closed 167 // If `openedFile` is null, it's because the last pane was closed
168 // and there is now an empty pane. 168 // and there is now an empty pane.
169 if (openedFile) { 169 if (openedFile) {
170 var activeView = this.app.workspace.getActiveViewOfType(MarkdownView); 170 var activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
171 this.registerOnUnloadFile(activeView); 171 if (activeView) {
172 172 this.registerOnUnloadFile(activeView);
173 if (!this._suppressNextFileOpen) { 173
174 this.restoreFileState(openedFile, activeView); 174 if (!this._suppressNextFileOpen) {
175 } else { 175 this.restoreFileState(openedFile, activeView);
176 this._suppressNextFileOpen = false; 176 }
177 } 177 }
178 // else: the file isn't handled by a markdown editor.
179
180 this._suppressNextFileOpen = false;
178 } 181 }
179 } 182 }
180 183
181 private readonly rememberFileState = async (file: TFile, view: View): Promise<void> => { 184 private readonly rememberFileState = async (file: TFile, view: View): Promise<void> => {
182 const scrollInfo = view.editor.getScrollInfo(); 185 const scrollInfo = view.editor.getScrollInfo();