┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Moerschell <[email protected]>2025-01-31 19:52:09 +0100
committerThomas Moerschell <[email protected]>2025-02-01 13:56:11 +0100
commitc7d6b98fa2aaecbd7f31b9c5976a753508532742 (patch)
tree8f11783696a6b0d476cc121ab7622bd22a41f540 /src
parent4b48c1b4af3f1fa585d7e1522a45b40c7af3cddf (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')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp20
-rw-r--r--src/tests/kfileitemmodeltest.cpp11
2 files changed, 28 insertions, 3 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;
}
}
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp
index 4b1814391..4c6db590d 100644
--- a/src/tests/kfileitemmodeltest.cpp
+++ b/src/tests/kfileitemmodeltest.cpp
@@ -1357,7 +1357,7 @@ void KFileItemModelTest::testIndexForKeyboardSearch()
{
QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
- m_testDir->createFiles({"a", "aa", "Image.jpg", "Image.png", "Text", "Text1", "Text2", "Text11"});
+ m_testDir->createFiles({"a", "aa", "Image.jpg", "Image.png", "Text", "Text1", "Text2", "Text11", "U", "Ü", "Üu", "Ž"});
m_model->loadDirectory(m_testDir->url());
QVERIFY(itemsInsertedSpy.wait());
@@ -1374,6 +1374,9 @@ void KFileItemModelTest::testIndexForKeyboardSearch()
QCOMPARE(m_model->indexForKeyboardSearch("text1", 0), 5);
QCOMPARE(m_model->indexForKeyboardSearch("text2", 0), 6);
QCOMPARE(m_model->indexForKeyboardSearch("text11", 0), 7);
+ QCOMPARE(m_model->indexForKeyboardSearch("u", 0), 8);
+ QCOMPARE(m_model->indexForKeyboardSearch("üu", 0), 10);
+ QCOMPARE(m_model->indexForKeyboardSearch("ž", 0), 11);
// Start a search somewhere in the middle
QCOMPARE(m_model->indexForKeyboardSearch("a", 1), 1);
@@ -1400,6 +1403,12 @@ void KFileItemModelTest::testIndexForKeyboardSearch()
QCOMPARE(m_model->indexForKeyboardSearch("TexT", 5), 5);
QCOMPARE(m_model->indexForKeyboardSearch("IMAGE", 4), 2);
+ // Test searches that match items with marks
+ QCOMPARE(m_model->indexForKeyboardSearch("u", 9), 9);
+ QCOMPARE(m_model->indexForKeyboardSearch("u", 10), 10);
+ QCOMPARE(m_model->indexForKeyboardSearch("uu", 0), 10);
+ QCOMPARE(m_model->indexForKeyboardSearch("z", 0), 11);
+
// TODO: Maybe we should also test keyboard searches in directories which are not sorted by Name?
}