Skip to content

Commit

Permalink
Fix: Search functionality in the body tab (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamarjun authored Jan 3, 2025
1 parent cdd74be commit 66da10c
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ internal class TransactionBodyAdapter(private val onCopyBodyListener: () -> Unit
foregroundColor: Int,
): List<SearchItemBodyLine> {
val listOfSearchItems = arrayListOf<SearchItemBodyLine>()
items.filterIsInstance<TransactionPayloadItem.BodyLineItem>()
.withIndex()
items.withIndex()
.forEach { (index, item) ->
if (item !is TransactionPayloadItem.BodyLineItem) return@forEach
val listOfOccurrences = item.line.indicesOf(newText)
if (listOfOccurrences.isNotEmpty()) {
// storing the occurrences and their positions
listOfOccurrences.forEach {
listOfSearchItems.add(
SearchItemBodyLine(
indexBodyLine = index + 1,
indexBodyLine = index,
indexStartOfQuerySubString = it,
),
)
Expand All @@ -114,12 +114,12 @@ internal class TransactionBodyAdapter(private val onCopyBodyListener: () -> Unit
backgroundColor,
foregroundColor,
)
notifyItemChanged(index + 1)
notifyItemChanged(index)
} else {
// Let's clear the spans if we haven't found the query string.
val removedSpansCount = item.line.clearHighlightSpans()
if (removedSpansCount > 0) {
notifyItemChanged(index + 1)
notifyItemChanged(index)
}
}
}
Expand Down Expand Up @@ -147,12 +147,12 @@ internal class TransactionBodyAdapter(private val onCopyBodyListener: () -> Unit
}

internal fun resetHighlight() {
items.filterIsInstance<TransactionPayloadItem.BodyLineItem>()
.withIndex()
items.withIndex()
.forEach { (index, item) ->
if (item !is TransactionPayloadItem.BodyLineItem) return@forEach
val removedSpansCount = item.line.clearHighlightSpans()
if (removedSpansCount > 0) {
notifyItemChanged(index + 1)
notifyItemChanged(index)
}
}
}
Expand Down

0 comments on commit 66da10c

Please sign in to comment.