Commit c4e87a0
committed
Refactor: Drastically simplify HighlightedText with fallback for crash avoidance
This commit significantly simplifies the `HighlightedText` composable to prioritize crash avoidance and minimize code, based on your feedback.
The new logic is as follows:
1. If the `pattern` is empty, the original `text` is displayed without highlighting.
2. If the `pattern` matches the entire `text` (case-insensitively), the original `text` is displayed without any highlighting. This serves as a simple fallback to prevent a suspected `IndexOutOfBoundsException` that might occur when applying styles to the entire string length in the specific Compose version used.
3. For all other cases (i.e., `pattern` is not empty and does not match the entire `text`), the original, compact `text.split()`-based highlighting logic is used. This method highlights occurrences of the pattern but uses the casing of the input `pattern` string for the styled segments, not necessarily the casing of the matched text.
This change rolls back more complex highlighting logic (like span splitting for full matches and case-preserving partial match highlighting via Regex/while loops) in favor of utmost simplicity and robustness against the reported crash.1 parent 6b7a5eb commit c4e87a0
1 file changed
Lines changed: 13 additions & 5 deletions
File tree
- android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/ui/composables
Lines changed: 13 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
| |||
47 | 55 | | |
48 | 56 | | |
49 | 57 | | |
50 | | - | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | 61 | | |
| |||
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
59 | | - | |
| 67 | + | |
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
| |||
67 | 75 | | |
68 | 76 | | |
69 | 77 | | |
70 | | - | |
| 78 | + | |
71 | 79 | | |
72 | 80 | | |
73 | 81 | | |
0 commit comments