Also trim search strings in highlights

This commit is contained in:
Dennis Felsing 2024-07-24 15:23:05 +02:00
parent a84a53c5fe
commit 1c2d7262d0

View file

@ -1784,21 +1784,24 @@ bool CMenus::PrintHighlighted(const char *pName, F &&PrintFn)
{
const char *pStr = g_Config.m_BrFilterString;
char aFilterStr[sizeof(g_Config.m_BrFilterString)];
char aFilterStrTrimmed[sizeof(g_Config.m_BrFilterString)];
while((pStr = str_next_token(pStr, IServerBrowser::SEARCH_EXCLUDE_TOKEN, aFilterStr, sizeof(aFilterStr))))
{
str_copy(aFilterStrTrimmed, str_utf8_skip_whitespaces(aFilterStr));
str_utf8_trim_right(aFilterStrTrimmed);
// highlight the parts that matches
const char *pFilteredStr;
int FilterLen = str_length(aFilterStr);
if(aFilterStr[0] == '"' && aFilterStr[FilterLen - 1] == '"')
int FilterLen = str_length(aFilterStrTrimmed);
if(aFilterStrTrimmed[0] == '"' && aFilterStrTrimmed[FilterLen - 1] == '"')
{
aFilterStr[FilterLen - 1] = '\0';
pFilteredStr = str_comp(pName, &aFilterStr[1]) == 0 ? pName : nullptr;
aFilterStrTrimmed[FilterLen - 1] = '\0';
pFilteredStr = str_comp(pName, &aFilterStrTrimmed[1]) == 0 ? pName : nullptr;
FilterLen -= 2;
}
else
{
const char *pFilteredStrEnd;
pFilteredStr = str_utf8_find_nocase(pName, aFilterStr, &pFilteredStrEnd);
pFilteredStr = str_utf8_find_nocase(pName, aFilterStrTrimmed, &pFilteredStrEnd);
if(pFilteredStr != nullptr && pFilteredStrEnd != nullptr)
FilterLen = pFilteredStrEnd - pFilteredStr;
}