diff options
| author | Thomas Moerschell <[email protected]> | 2025-01-31 19:52:09 +0100 |
|---|---|---|
| committer | Thomas Moerschell <[email protected]> | 2025-02-01 13:56:11 +0100 |
| commit | c7d6b98fa2aaecbd7f31b9c5976a753508532742 (patch) | |
| tree | 8f11783696a6b0d476cc121ab7622bd22a41f540 /src/kitemviews/kfileitemmodel.cpp | |
| parent | 4b48c1b4af3f1fa585d7e1522a45b40c7af3cddf (diff) | |
Ignore diacritical marks for keyboard search
When using keyboard search, normalize the item names and remove marks
first. Now, items containing characters with marks can be found using
keyboard search.
BUG: 482394
Diffstat (limited to 'src/kitemviews/kfileitemmodel.cpp')
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index f8c30b9e4..40ec09507 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -335,16 +335,32 @@ QMimeData *KFileItemModel::createMimeData(const KItemSet &indexes) const return data; } +namespace +{ +QString removeMarks(const QString &original) +{ + const auto normalized = original.normalized(QString::NormalizationForm_D); + QString res; + for (auto ch : normalized) { + if (!ch.isMark()) { + res.append(ch); + } + } + return res; +} +} + int KFileItemModel::indexForKeyboardSearch(const QString &text, int startFromIndex) const { + const auto noMarkText = removeMarks(text); startFromIndex = qMax(0, startFromIndex); for (int i = startFromIndex; i < count(); ++i) { - if (fileItem(i).text().startsWith(text, Qt::CaseInsensitive)) { + if (removeMarks(fileItem(i).text()).startsWith(noMarkText, Qt::CaseInsensitive)) { return i; } } for (int i = 0; i < startFromIndex; ++i) { - if (fileItem(i).text().startsWith(text, Qt::CaseInsensitive)) { + if (removeMarks(fileItem(i).text()).startsWith(noMarkText, Qt::CaseInsensitive)) { return i; } } |
