Commit 1fad1ba
committed
Fix: Workaround for IndexOutOfBoundsException in Compose text rendering
The crash `java.lang.IndexOutOfBoundsException: setSpan (0 ... X) ends beyond length Y`
is hypothesized to occur when the Compose text system applies a default
paragraph-level style with an incorrectly calculated end range (length + 1),
particularly after the text content has been processed (e.g., newlines stripped
by `App.kt#getCommandList`).
This commit introduces a workaround in `CommandView.kt`:
- The `AnnotatedString` generated from command elements (which has newlines
already stripped by `App.kt` to maintain UI consistency) is now explicitly
assigned a `ParagraphStyle()` covering its correct range `(0, text.length)`.
- This is intended to prevent the text system from applying a default
paragraph style with a miscalculated range, by providing a specific style
for the entire text with correct boundaries.
The newline stripping behavior in `App.kt#getCommandList` remains as it was
originally, to ensure no unintended changes to UI layout regarding line breaks.
Further testing by running the application is crucial to confirm that this
workaround resolves the crash and does not negatively impact UI or performance.1 parent 20fa684 commit 1fad1ba
2 files changed
Lines changed: 20 additions & 4 deletions
File tree
- android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/ui/composables
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | | - | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
100 | 116 | | |
101 | 117 | | |
102 | | - | |
| 118 | + | |
103 | 119 | | |
104 | 120 | | |
105 | 121 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
0 commit comments