Skip to content

Commit a478a62

Browse files
author
Jan Guegel
committed
compare normalized search and items to ignore accents and diacritics
1 parent 223e644 commit a478a62

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Fixed folders showing up incorrectly as files in copy/move dialog ([#267])
1010
- Fixed error when saving files with unsupported characters ([#250])
1111
- Fixed missing permission prompt on initial "Save as" launch ([#85])
12+
- Search - Ignore accents and diacritics ([#95])
1213

1314
## [1.2.3] - 2025-09-15
1415
### Fixed
@@ -78,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7879
[#267]: https://github.com/FossifyOrg/File-Manager/issues/267
7980
[#250]: https://github.com/FossifyOrg/File-Manager/issues/250
8081
[#85]: https://github.com/FossifyOrg/File-Manager/issues/85
82+
[#85]: https://github.com/FossifyOrg/File-Manager/issues/95
8183

8284
[Unreleased]: https://github.com/FossifyOrg/File-Manager/compare/1.2.3...HEAD
8385
[1.2.3]: https://github.com/FossifyOrg/File-Manager/compare/1.2.2...1.2.3

app/src/main/kotlin/org/fossify/filemanager/fragments/ItemsFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
377377
return files
378378
}
379379

380+
val normalizedText = text.normalizeText()
380381
val sorting = context!!.config.getFolderSorting(path)
381382
FileDirItem.sorting = context!!.config.getFolderSorting(currentPath)
382383
val isSortingBySize = sorting and SORT_BY_SIZE != 0
@@ -386,7 +387,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
386387
}
387388

388389
if (it.isDirectory) {
389-
if (it.name.contains(text, true)) {
390+
if (it.name.normalizeText().contains(normalizedText)) {
390391
val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap(), false)
391392
if (fileDirItem != null) {
392393
files.add(fileDirItem)
@@ -395,7 +396,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
395396

396397
files.addAll(searchFiles(text, it.absolutePath))
397398
} else {
398-
if (it.name.contains(text, true)) {
399+
if (it.name.normalizeText().contains(normalizedText)) {
399400
val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap(), false)
400401
if (fileDirItem != null) {
401402
files.add(fileDirItem)

app/src/main/kotlin/org/fossify/filemanager/fragments/MyViewPagerFragment.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.fossify.filemanager.fragments
22

33
import android.content.Context
4+
import android.icu.text.Normalizer2
45
import android.util.AttributeSet
56
import android.widget.RelativeLayout
67
import org.fossify.commons.extensions.*
@@ -16,6 +17,7 @@ import org.fossify.filemanager.databinding.StorageFragmentBinding
1617
import org.fossify.filemanager.extensions.isPathOnRoot
1718
import org.fossify.filemanager.extensions.tryOpenPathIntent
1819
import org.fossify.filemanager.helpers.RootHelpers
20+
import java.util.Locale
1921

2022
abstract class MyViewPagerFragment<BINDING : MyViewPagerFragment.InnerBinding>(context: Context, attributeSet: AttributeSet) :
2123
RelativeLayout(context, attributeSet) {
@@ -88,6 +90,13 @@ abstract class MyViewPagerFragment<BINDING : MyViewPagerFragment.InnerBinding>(c
8890
}
8991
}
9092

93+
protected fun String.normalizeText(): String {
94+
val normalizer = Normalizer2.getNFDInstance()
95+
return normalizer.normalize(this)
96+
.replace("\\p{M}".toRegex(), "")
97+
.lowercase(Locale.getDefault())
98+
}
99+
91100
abstract fun setupFragment(activity: SimpleActivity)
92101

93102
abstract fun onResume(textColor: Int)

app/src/main/kotlin/org/fossify/filemanager/fragments/RecentsFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
242242

243243
override fun searchQueryChanged(text: String) {
244244
lastSearchedText = text
245-
val filtered = filesIgnoringSearch.filter { it.mName.contains(text, true) }.toMutableList() as ArrayList<ListItem>
245+
val normalizedText = text.normalizeText()
246+
val filtered = filesIgnoringSearch.filter {
247+
it.mName.normalizeText().contains(normalizedText)
248+
}.toMutableList() as ArrayList<ListItem>
249+
246250
binding.apply {
247251
(recentsList.adapter as? ItemsAdapter)?.updateItems(filtered, text)
248252
recentsPlaceholder.beVisibleIf(filtered.isEmpty())

0 commit comments

Comments
 (0)