From 6b466f8695ef479521a8b8e49e9464136886c592 Mon Sep 17 00:00:00 2001 From: d0vgan Date: Sat, 20 Jan 2024 21:24:33 +0200 Subject: [PATCH] now findFileNameIndexInNppOpenFileNames checks the current file first --- NppExec/src/NppExec.cpp | 44 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/NppExec/src/NppExec.cpp b/NppExec/src/NppExec.cpp index 40a63c1..b1c6a98 100644 --- a/NppExec/src/NppExec.cpp +++ b/NppExec/src/NppExec.cpp @@ -2580,19 +2580,7 @@ char* CNppExec::convertSciText(char* pSciText, int nTextLen, int nSciCodePage, e int CNppExec::findFileNameIndexInNppOpenFileNames(const tstr& fileName, bool bGetOpenFileNames, int nView ) { - if (bGetOpenFileNames) - { - if (nView == PRIMARY_VIEW || nView == SECOND_VIEW) - { - npp_nbFiles = nppGetOpenFileNamesInView(nView); - } - else - nppGetOpenFileNames(); - } - - tstr S; tstr S1 = NppExecHelpers::NormalizePath(fileName); - int nFileLevel = 0; bool bFullPath = NppExecHelpers::IsFullPath(S1); if (!bFullPath) @@ -2606,6 +2594,38 @@ int CNppExec::findFileNameIndexInNppOpenFileNames(const tstr& fileName, bool bGe NppExecHelpers::StrUpper(S1); + if (!bFullPath) + { + // checking the current (active) file first + tstr filePath; + filePath.Reserve(FILEPATH_BUFSIZE); + SendNppMsg(NPPM_GETFULLCURRENTPATH, (WPARAM) (filePath.GetMemSize() - 1), (LPARAM) filePath.data()); + filePath.CalculateLength(); + if (filePath.length() > S1.length()) + { + if (filePath.GetAt(filePath.length() - S1.length() - 1) == _T('\\')) + { + NppExecHelpers::StrUpper(filePath); + if (filePath.EndsWith(S1)) + { + S1 = filePath; + bFullPath = true; + } + } + } + } + + if (bGetOpenFileNames) + { + if (nView == PRIMARY_VIEW || nView == SECOND_VIEW) + { + npp_nbFiles = nppGetOpenFileNamesInView(nView); + } + else + nppGetOpenFileNames(); + } + + tstr S; int iPartialMatch1 = -1; int iFind1 = -1; for (int i = 0; i < npp_nbFiles; ++i)