From a36a83a7a044fa98a4d11b671d5b17fc2d9fa477 Mon Sep 17 00:00:00 2001 From: deep-soft Date: Sun, 1 Sep 2024 23:56:13 +0300 Subject: [PATCH] soft_fast_search-nyq Expanded file panel fast search functionality to also search for matches in the middle of the string if search in the beginning of the string was unsuccessful. This is very helpful in two scenarios: 1) When no exact match in the beginning of the filename string was found, but user would like to also find matches in the middle of the filenames. 2) When directory contains files that start with characters that can't be easily entered into fast search box like '[' and '{', yet the user would like to search beyond these characters. soft_fast_search (FarGroup/FarManager#862) @nyq nyq committed last month 1 parent d61cbf7 commit d9a16fb --- far/filelist.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/far/filelist.cpp b/far/filelist.cpp index 0f0ecf933c..ad429ecce3 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -1,4 +1,4 @@ -/* +/* filelist.cpp Файловая панель @@ -3690,7 +3690,7 @@ bool FileList::FindPartName(string_view const Name,int Next,int Direct) NameView.remove_suffix(1); } - const auto strMask = exclude_sets(NameView + L'*'); + auto strMask = exclude_sets(NameView + L'*'); const auto Match = [&](int const I) { @@ -3710,17 +3710,24 @@ bool FileList::FindPartName(string_view const Name,int Next,int Direct) return false; }; - - for (int I=m_CurFile+(Next?Direct:0); I >= 0 && I < static_cast(m_ListData.size()); I+=Direct) + //Две попытки найти нужный файл - сначала строгий поиск по началам строк, потом более мягкий по серединам строк + //TODO: в будущем можно добавить опцию в настройки (выполнять или не выполнять вторую попытку) + for (int attempt=0; attempt<2; attempt++) { - if (Match(I)) - return true; - } + for (int I=m_CurFile+(Next?Direct:0); I >= 0 && I < static_cast(m_ListData.size()); I+=Direct) + { + if (Match(I)) + return true; + } - for (int I=(Direct > 0)?0:static_cast(m_ListData.size()-1); (Direct > 0) ? I < m_CurFile:I > m_CurFile; I+=Direct) - { - if (Match(I)) - return true; + for (int I=(Direct > 0)?0:static_cast(m_ListData.size()-1); (Direct > 0) ? I < m_CurFile:I > m_CurFile; I+=Direct) + { + if (Match(I)) + return true; + } + //Смягчаем критерий поиска, если строгий поиск ни к чему не привёл, и повторяем попытку + if (!strMask.starts_with(L'*')) + strMask = L'*' + strMask; } return false;