From 342d46b0fea631c2d35201f0dd53f39cff7e0e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melvyn=20La=C3=AFly?= Date: Sun, 7 Jan 2024 21:56:05 +0100 Subject: [PATCH] Fix always empty search results when using a backend that doesn't return highlights This notably happens with Synapse on SQLite. --- changelog.d/8729.bugfix | 1 + .../home/room/detail/search/SearchResultController.kt | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 changelog.d/8729.bugfix diff --git a/changelog.d/8729.bugfix b/changelog.d/8729.bugfix new file mode 100644 index 00000000000..3078bd1fcb4 --- /dev/null +++ b/changelog.d/8729.bugfix @@ -0,0 +1 @@ +Fix always empty search results when using a backend that doesn't return highlights (e.g. Synapse on SQLite) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt index 71c0427c974..a11ff982a21 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchResultController.kt @@ -148,6 +148,13 @@ class SearchResultController @Inject constructor( */ private fun setHighLightedText(text: String, highlights: List): Spannable? { val wordToSpan: Spannable = SpannableString(text) + + // Some backends don't return highlights at all (this is the case of Synapse with the SQLite storage). + // In this case, don't attempt to filter based on the highlights, to avoid erasing all the results... + if (highlights.isEmpty()) { + return wordToSpan + } + var found = false highlights.forEach { highlight -> var searchFromIndex = 0