Commit b9d5739b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Improve search

parent 4f9e526a
Pipeline #148081 passed with stage
in 1 minute and 19 seconds
......@@ -9,6 +9,32 @@
#include <KLocalizedString>
static QString normalize(QStringView str)
{
QString out;
out.reserve(str.size());
for (const auto c : str) {
// case folding
const auto n = c.toCaseFolded();
// if the character has a canonical decomposition use that and skip the
// combining diacritic markers following it
// see https://en.wikipedia.org/wiki/Unicode_equivalence
// see https://en.wikipedia.org/wiki/Combining_character
if (n.decompositionTag() == QChar::Canonical) {
out.push_back(n.decomposition().at(0));
}
// handle compatibility compositions such as ligatures
// see https://en.wikipedia.org/wiki/Unicode_compatibility_characters
else if (n.decompositionTag() == QChar::Compat && n.isLetter() && n.script() == QChar::Script_Latin) {
out.append(n.decomposition());
} else {
out.push_back(n);
}
}
return out;
}
KNotesListWidgetSearchLine::KNotesListWidgetSearchLine(QWidget *parent)
: KListWidgetSearchLine(parent)
{
......@@ -31,10 +57,11 @@ bool KNotesListWidgetSearchLine::itemMatches(const QListWidgetItem *item, const
if (!iconView) {
return false;
}
if (iconView->realName().contains(s)) {
const QString strNormalize{normalize(s)};
if (normalize(iconView->realName()).contains(strNormalize)) {
return true;
}
if (iconView->description().contains(s)) {
if (normalize(iconView->description()).contains(strNormalize)) {
return true;
}
return KListWidgetSearchLine::itemMatches(item, s);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment