From a51e62c16dc45160afe6c7deb19096e98ad18372 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 5 Dec 2023 04:55:49 +0100 Subject: [PATCH] Fix cloned (modified & unsaved) document disassociated issue after Npp being relaunched The bug has been fixed in v8.5.7 by PR #14003. However the fix causes a regression #14164, the concerning commit is reverted. Hence this fix. Fix #10266, fix #10365 --- PowerEditor/src/NppIO.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 33d745bec..083032cff 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -2276,17 +2276,21 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch nppParam.safeWow64EnableWow64FsRedirection(FALSE); isWow64Off = true; } + if (PathFileExists(pFn)) { - if (isSnapshotMode && session._subViewFiles[k]._backupFilePath != TEXT("")) - lastOpened = doOpen(pFn, false, false, session._subViewFiles[k]._encoding, session._subViewFiles[k]._backupFilePath.c_str(), session._subViewFiles[k]._originalFileLastModifTimestamp); - else - lastOpened = doOpen(pFn, false, false, session._subViewFiles[k]._encoding); - //check if already open in main. If so, clone - if (_mainDocTab.getIndexByBuffer(lastOpened) != -1) + BufferID clonedBuf = _mainDocTab.findBufferByName(pFn); + if (clonedBuf != BUFFER_INVALID) + { + loadBufferIntoView(clonedBuf, SUB_VIEW); + } + else { - loadBufferIntoView(lastOpened, SUB_VIEW); + if (isSnapshotMode && session._subViewFiles[k]._backupFilePath != TEXT("")) + lastOpened = doOpen(pFn, false, false, session._subViewFiles[k]._encoding, session._subViewFiles[k]._backupFilePath.c_str(), session._subViewFiles[k]._originalFileLastModifTimestamp); + else + lastOpened = doOpen(pFn, false, false, session._subViewFiles[k]._encoding); } } else if (isSnapshotMode && PathFileExists(session._subViewFiles[k]._backupFilePath.c_str())) @@ -2299,6 +2303,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch if (foundBufID == BUFFER_INVALID) lastOpened = nppGUI._keepSessionAbsentFileEntries ? MainFileManager.newPlaceholderDocument(pFn, SUB_VIEW, userCreatedSessionName) : BUFFER_INVALID; } + if (isWow64Off) { nppParam.safeWow64EnableWow64FsRedirection(TRUE);