# HG changeset patch # User Ludovic Chabant # Date 1657834604 25200 # Node ID fbaf7c7126be591ee5a1cf4ea2acbf6b42e2b30a # Parent 3d0ac176118f60798c7119c325f095339ec14df4 Don't restore file state if we're just switching to another pane To do this we have to track the opened file path in the new editor view and check if it matches the last file path we knew for that view. diff -r 3d0ac176118f -r fbaf7c7126be src/main.ts --- a/src/main.ts Sat May 14 09:33:19 2022 -0700 +++ b/src/main.ts Thu Jul 14 14:36:44 2022 -0700 @@ -91,6 +91,9 @@ // Next unique ID to identify views without keeping references to them. private _nextUniqueViewId: number = 0; + // Remember last open file in each view. + private _lastOpenFiles: Record = {}; + // Functions to unregister any monkey-patched view hooks on plugin unload. private _viewUninstallers: Record = {}; // Functions to unregister any global callbacks on plugin unload. @@ -164,6 +167,7 @@ }); console.debug(`Unregistered ${numViews} view callbacks`); this._viewUninstallers = {}; + this._lastOpenFiles = {}; // Run global unhooks. this._globalUninstallers.forEach((cb) => cb()); @@ -181,7 +185,6 @@ var filePath = view.file.path; var viewId = this.getUniqueViewId(view as unknown as ViewWithID, true); if (viewId in this._viewUninstallers) { - console.debug(`View ${viewId} is already registered`, filePath); return; } @@ -206,6 +209,7 @@ if (plugin) { console.debug(`Unregistering view ${viewId} callback`, filePath); delete plugin._viewUninstallers[viewId]; + delete plugin._lastOpenFiles[viewId]; uninstall(); } else { console.debug( @@ -224,11 +228,24 @@ if (activeView) { this.registerOnUnloadFile(activeView); + var isRealFileOpen = true; + const viewId = this.getUniqueViewId(activeView as ViewWithID); + if (viewId != undefined) { + const lastOpenFileInView = this._lastOpenFiles[viewId]; + isRealFileOpen = (lastOpenFileInView != openedFile.path); + this._lastOpenFiles[viewId] = openedFile.path; + } + // Don't restore the file state if: // - We are suppressing it explicitly (such as if the file was - // opened via clicking a hyperlink) + // opened via clicking a hyperlink) // - The file is already currently open in another pane - if (!this._suppressNextFileOpen && !this.isFileMultiplyOpen(openedFile)) { + // - The file was already opened in this pane, and we're just + // returning to it. + if (!this._suppressNextFileOpen && + !this.isFileMultiplyOpen(openedFile) && + isRealFileOpen + ) { try { this.restoreFileState(openedFile, activeView); } catch (err) {