Skip to content

Commit

Permalink
soft_fast_search-nyq
Browse files Browse the repository at this point in the history
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#862)
@nyq
nyq committed last month 
1 parent d61cbf7
commit d9a16fb
  • Loading branch information
deep-soft authored Sep 1, 2024
1 parent 12f9258 commit a36a83a
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions far/filelist.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
filelist.cpp
Файловая панель
Expand Down Expand Up @@ -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)
{
Expand All @@ -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<int>(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<int>(m_ListData.size()); I+=Direct)
{
if (Match(I))
return true;
}

for (int I=(Direct > 0)?0:static_cast<int>(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<int>(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;
Expand Down

0 comments on commit a36a83a

Please sign in to comment.