Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you removed this?

Copy link
Copy Markdown
Contributor Author

@iamarjun iamarjun Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since TransactionPayloadItem have mutliple types, filtering the BodyLineItem subtype and then indexing them does't really give us the actual index of the item in the whole list. As a result wrong line with wrong search query gets highlighted, also the primary reason for the crash as well

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I understand. Thanks for clarifying πŸ‘

.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