From fc736d8afb8a7259f3e9a35af4498819c5523637 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 19 Aug 2023 18:05:15 +0200 Subject: [PATCH] Fix activating wrong file(s) issue after loading session file ... if some files are already opened in Notepad++. Fix #14006, close #14028 --- PowerEditor/src/NppIO.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index d7375ea20..488546c64 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -2353,11 +2353,21 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou _mainEditView.restoreCurrentPosPreStep(); _subEditView.restoreCurrentPosPreStep(); - if (session._activeMainIndex < _mainDocTab.nbItem())//session.nbMainFiles()) - activateBuffer(_mainDocTab.getBufferByIndex(session._activeMainIndex), MAIN_VIEW); + if (session._activeMainIndex < session._mainViewFiles.size()) + { + const wchar_t* fileName = session._mainViewFiles[session._activeMainIndex]._fileName.c_str(); + BufferID buf = _mainDocTab.findBufferByName(fileName); + if (buf != BUFFER_INVALID) + activateBuffer(buf, MAIN_VIEW); + } - if (session._activeSubIndex < _subDocTab.nbItem())//session.nbSubFiles()) - activateBuffer(_subDocTab.getBufferByIndex(session._activeSubIndex), SUB_VIEW); + if (session._activeSubIndex < session._subViewFiles.size()) + { + const wchar_t* fileName = session._subViewFiles[session._activeSubIndex]._fileName.c_str(); + BufferID buf = _subDocTab.findBufferByName(fileName); + if (buf != BUFFER_INVALID) + activateBuffer(buf, SUB_VIEW); + } if ((session.nbSubFiles() > 0) && (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW)) switchEditViewTo(static_cast(session._activeView));