From d9a16fbdacf984f7283bcc3c48add73c5b8ae396 Mon Sep 17 00:00:00 2001 From: Nyq <623434+nyq@users.noreply.github.com> Date: Fri, 2 Aug 2024 20:07:31 -0400 Subject: [PATCH] Update filelist.cpp 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. --- 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;