Skip to content

Commit

Permalink
chore: Change user search name surname highlight logic #WPB-6536 (#3545)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-zagorski authored Oct 24, 2024
1 parent aad6b54 commit af36e51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ fun HighlightName(
modifier: Modifier = Modifier
) {

val queryWithoutSuffix = searchQuery.removeQueryPrefix()

val highlightIndexes = QueryMatchExtractor.extractQueryMatchIndexes(
matchText = queryWithoutSuffix,
matchText = searchQuery,
text = name
)

if (queryWithoutSuffix != String.EMPTY && highlightIndexes.isNotEmpty()) {
if (searchQuery != String.EMPTY && highlightIndexes.isNotEmpty()) {
Text(
buildAnnotatedString {
withStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ fun HighlightSubtitle(
return
}

val queryWithoutSuffix = searchQuery.removeQueryPrefix()
val subtitleWithPrefix = "$prefix$subTitle"

val highlightIndexes = QueryMatchExtractor.extractQueryMatchIndexes(
matchText = queryWithoutSuffix,
text = subTitle
matchText = searchQuery,
text = subtitleWithPrefix
)

if (queryWithoutSuffix != String.EMPTY && highlightIndexes.isNotEmpty()) {
if (searchQuery != String.EMPTY && highlightIndexes.isNotEmpty()) {
Text(
buildAnnotatedString {
withStyle(
Expand All @@ -59,7 +59,7 @@ fun HighlightSubtitle(
fontStyle = MaterialTheme.wireTypography.subline01.fontStyle
)
) {
append("$prefix$subTitle")
append(subtitleWithPrefix)
}

highlightIndexes
Expand All @@ -70,8 +70,8 @@ fun HighlightSubtitle(
background = MaterialTheme.wireColorScheme.highlight,
color = MaterialTheme.wireColorScheme.onHighlight,
),
start = highLightIndex.startIndex + prefix.length,
end = highLightIndex.endIndex + prefix.length
start = highLightIndex.startIndex,
end = highLightIndex.endIndex
)
}
}
Expand All @@ -81,7 +81,7 @@ fun HighlightSubtitle(
)
} else {
Text(
text = "$prefix$subTitle",
text = subtitleWithPrefix,
style = MaterialTheme.wireTypography.subline01,
color = MaterialTheme.wireColorScheme.secondaryText,
maxLines = 1,
Expand Down

0 comments on commit af36e51

Please sign in to comment.