Skip to content

Commit 154cadd

Browse files
author
Simon Schubert
committed
Fix highlight
1 parent c4e87a0 commit 154cadd

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/ui/composables/CommandView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fun CommandView(
107107
addStyle(
108108
style = ParagraphStyle(), // Default ParagraphStyle
109109
start = 0,
110-
end = baseAnnotatedString.text.length
110+
end = baseAnnotatedString.text.length,
111111
)
112112
}
113113
}

android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/ui/composables/HighlightedText.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@ fun HighlightedText(
3434
) {
3535
if (pattern.isEmpty()) {
3636
Text(
37-
text = text, // Explicitly naming arguments for clarity
37+
text = text,
3838
maxLines = maxLines,
39-
overflow = TextOverflow.Ellipsis
39+
overflow = TextOverflow.Ellipsis,
4040
)
4141
} else if (text.equals(pattern, ignoreCase = true)) {
42-
// Fallback for full-text match to avoid potential crash
4342
Text(
4443
text = text,
4544
maxLines = maxLines,
46-
overflow = TextOverflow.Ellipsis
45+
overflow = TextOverflow.Ellipsis,
46+
color = MaterialTheme.colors.primary,
4747
)
4848
} else {
49-
// Original compact highlighting logic for partial matches
5049
val highlightColor = MaterialTheme.colors.primary
5150
val annotatedString = remember(text, pattern, highlightColor) {
5251
buildAnnotatedString {
@@ -55,7 +54,7 @@ fun HighlightedText(
5554
append(s)
5655
if (index != splitText.size - 1) {
5756
withStyle(style = SpanStyle(color = highlightColor)) {
58-
append(pattern) // Appends the pattern string directly
57+
append(pattern)
5958
}
6059
}
6160
}
@@ -64,7 +63,7 @@ fun HighlightedText(
6463
Text(
6564
text = annotatedString,
6665
maxLines = maxLines,
67-
overflow = TextOverflow.Ellipsis
66+
overflow = TextOverflow.Ellipsis,
6867
)
6968
}
7069
}
@@ -75,7 +74,7 @@ fun HighlightedTextPreview() {
7574
LinuxTheme {
7675
HighlightedText(
7776
text = "pacman",
78-
pattern = "cm"
77+
pattern = "cm",
7978
)
8079
}
8180
}

0 commit comments

Comments
 (0)