Fix regression "Open Selected PathName(s)" command not working with Ctrl-A

The regression is introduced by:
467182602a

The solution is from:
https://github.com/notepad-plus-plus/notepad-plus-plus/issues/15960#issuecomment-2553746218

Fix #15960
This commit is contained in:
Don Ho 2024-12-21 03:53:45 +01:00
parent 0447dc8988
commit 50c2c3a74a

View File

@ -691,7 +691,6 @@ void Finder::deleteResult()
vector<wstring> Finder::getResultFilePaths(bool onlyInSelectedText) const vector<wstring> Finder::getResultFilePaths(bool onlyInSelectedText) const
{ {
std::vector<wstring> paths;
size_t fromLine = 0, toLine = 0; size_t fromLine = 0, toLine = 0;
if (onlyInSelectedText) if (onlyInSelectedText)
@ -705,29 +704,32 @@ vector<wstring> Finder::getResultFilePaths(bool onlyInSelectedText) const
toLine = _scintView.execute(SCI_GETLINECOUNT) - 1; toLine = _scintView.execute(SCI_GETLINECOUNT) - 1;
} }
size_t len = _pMainFoundInfos->size(); // First, get the number of elements in the container size_t len = _pMainFoundInfos->size();
vector<wstring> paths;
for (size_t line = fromLine; line <= toLine; ++line) for (size_t line = fromLine; line <= toLine; ++line)
{ {
bool found = false; // Was it found?
const int lineFoldLevel = _scintView.execute(SCI_GETFOLDLEVEL, line) & SC_FOLDLEVELNUMBERMASK; const int lineFoldLevel = _scintView.execute(SCI_GETFOLDLEVEL, line) & SC_FOLDLEVELNUMBERMASK;
if (lineFoldLevel == fileHeaderLevel) if (lineFoldLevel == fileHeaderLevel)
{ {
line++; // Move to the next line // fileHeaderLevel lines don't have path info; have to look into the NEXT line for it,
if (line < len) // but only need to do something special here if we are on the LAST line of the selection
found = true; // Found it if (line == toLine)
} {
else if (lineFoldLevel == resultLevel) ++line;
{ }
if (line < len)
found = true; // Found it
} }
if (found) if (line < len)
{ {
wstring& path = (*_pMainFoundInfos)[line]._fullPath; wstring& path2add = (*_pMainFoundInfos)[line]._fullPath;
if (std::find(paths.begin(), paths.end(), path) == paths.end()) if (!path2add.empty())
{ {
paths.push_back(path); // make sure that path is not already in
if (std::find(paths.begin(), paths.end(), path2add) == paths.end())
{
paths.push_back(path2add);
}
} }
} }
} }
@ -735,6 +737,7 @@ vector<wstring> Finder::getResultFilePaths(bool onlyInSelectedText) const
return paths; return paths;
} }
bool Finder::canFind(const wchar_t *fileName, size_t lineNumber, size_t* indexToStartFrom) const bool Finder::canFind(const wchar_t *fileName, size_t lineNumber, size_t* indexToStartFrom) const
{ {
size_t len = _pMainFoundInfos->size(); size_t len = _pMainFoundInfos->size();