Skip to content

Commit fec28af

Browse files
authored
fix: search now ignores accents and diacritics (#274)
* compare normalized search and items to ignore accents and diacritics * Update CHANGELOG.md * compare normalized search and items to ignore accents and diacritics * Update CHANGELOG.md * fix change print enconding to base64 #104 Signed-off-by: Jan Guegel <[email protected]> * ops.. wrong branch.. Signed-off-by: Jan Guegel <[email protected]> * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: Naveen Singh <[email protected]> * use normalizeString() from commons libs Signed-off-by: Jan Guegel <[email protected]> * use normalizeString() from commons libs also for recentsfragmen Signed-off-by: Jan Guegel <[email protected]> * Apply suggestions from code review Co-authored-by: Naveen Singh <[email protected]> * use normalizeString() for StorageFragment Signed-off-by: Jan Guegel <[email protected]> * fix last usage of contains() without normalizeString in search context fix missing expection toast Signed-off-by: Jan Guegel <[email protected]> * remove Toast from loop Co-authored-by: Naveen Singh <[email protected]> --------- Signed-off-by: Jan Guegel <[email protected]> Co-authored-by: Jan Guegel <[email protected]> Co-authored-by: Naveen Singh <[email protected]> Refs: #95
1 parent eb4d38d commit fec28af

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
### Changed
1818
- Save button now overwrites files directly in the text editor ([#224])
19+
- Search now ignores accents and diacritics ([#95])
1920

2021
## [1.2.3] - 2025-09-15
2122
### Fixed
@@ -85,6 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8586
[#267]: https://github.com/FossifyOrg/File-Manager/issues/267
8687
[#250]: https://github.com/FossifyOrg/File-Manager/issues/250
8788
[#85]: https://github.com/FossifyOrg/File-Manager/issues/85
89+
[#95]: https://github.com/FossifyOrg/File-Manager/issues/95
8890
[#104]: https://github.com/FossifyOrg/File-Manager/issues/104
8991
[#224]: https://github.com/FossifyOrg/File-Manager/issues/224
9092

app/src/main/kotlin/org/fossify/filemanager/activities/MimeTypesActivity.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
133133
override fun selectedPaths(paths: ArrayList<String>) {}
134134

135135
fun searchQueryChanged(text: String) {
136-
val searchText = text.trim()
137-
lastSearchedText = searchText
136+
val normalizedText = text.normalizeString()
137+
val searchNormalizedText = normalizedText.trim()
138+
lastSearchedText = searchNormalizedText
138139
when {
139-
searchText.isEmpty() -> {
140+
searchNormalizedText.isEmpty() -> {
140141
binding.apply {
141142
mimetypesFastscroller.beVisible()
142143
getRecyclerAdapter()?.updateItems(storedItems)
@@ -145,7 +146,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
145146
}
146147
}
147148

148-
searchText.length == 1 -> {
149+
searchNormalizedText.length == 1 -> {
149150
binding.apply {
150151
mimetypesFastscroller.beGone()
151152
mimetypesPlaceholder.beVisible()
@@ -155,11 +156,13 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
155156

156157
else -> {
157158
ensureBackgroundThread {
158-
if (lastSearchedText != searchText) {
159+
if (lastSearchedText != searchNormalizedText) {
159160
return@ensureBackgroundThread
160161
}
161162

162-
val listItems = storedItems.filter { it.name.contains(searchText, true) } as ArrayList<ListItem>
163+
val listItems = storedItems.filter {
164+
it.name.normalizeString().contains(searchNormalizedText, true)
165+
} as ArrayList<ListItem>
163166

164167
runOnUiThread {
165168
getRecyclerAdapter()?.updateItems(listItems, text)

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.normalizeString()
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.normalizeString().contains(normalizedText, true)) {
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.normalizeString().contains(normalizedText, true)) {
399400
val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap(), false)
400401
if (fileDirItem != null) {
401402
files.add(fileDirItem)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.fossify.commons.extensions.getDoesFilePathExist
1212
import org.fossify.commons.extensions.getFilenameFromPath
1313
import org.fossify.commons.extensions.getLongValue
1414
import org.fossify.commons.extensions.getStringValue
15+
import org.fossify.commons.extensions.normalizeString
1516
import org.fossify.commons.extensions.showErrorToast
1617
import org.fossify.commons.helpers.VIEW_TYPE_GRID
1718
import org.fossify.commons.helpers.VIEW_TYPE_LIST
@@ -242,7 +243,11 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
242243

243244
override fun searchQueryChanged(text: String) {
244245
lastSearchedText = text
245-
val filtered = filesIgnoringSearch.filter { it.mName.contains(text, true) }.toMutableList() as ArrayList<ListItem>
246+
val normalizedText = text.normalizeString()
247+
val filtered = filesIgnoringSearch.filter {
248+
it.mName.normalizeString().contains(normalizedText, true)
249+
}.toMutableList() as ArrayList<ListItem>
250+
246251
binding.apply {
247252
(recentsList.adapter as? ItemsAdapter)?.updateItems(filtered, text)
248253
recentsPlaceholder.beVisibleIf(filtered.isEmpty())

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.fossify.commons.extensions.getLongValue
2828
import org.fossify.commons.extensions.getProperBackgroundColor
2929
import org.fossify.commons.extensions.getProperPrimaryColor
3030
import org.fossify.commons.extensions.getStringValue
31+
import org.fossify.commons.extensions.normalizeString
3132
import org.fossify.commons.extensions.queryCursor
3233
import org.fossify.commons.extensions.showErrorToast
3334
import org.fossify.commons.extensions.updateTextColors
@@ -340,6 +341,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
340341
}
341342

342343
override fun searchQueryChanged(text: String) {
344+
val normalizedText = text.normalizeString()
343345
lastSearchedText = text
344346
binding.apply {
345347
if (text.isNotEmpty()) {
@@ -364,7 +366,10 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
364366
} else {
365367
showProgressBar()
366368
ensureBackgroundThread {
367-
val filtered = allDeviceListItems.filter { it.mName.contains(text, true) }.toMutableList() as ArrayList<ListItem>
369+
val filtered = allDeviceListItems.filter {
370+
it.mName.normalizeString().contains(normalizedText, true)
371+
}.toMutableList() as ArrayList<ListItem>
372+
368373
if (lastSearchedText != text) {
369374
return@ensureBackgroundThread
370375
}

0 commit comments

Comments
 (0)