* Build a mapping from each character position in the plain text to its segment index. * Returns an array where charToSegment[i] is the segment index for character i.
(segments: StyledSegment[])
| 190 | * Returns an array where charToSegment[i] is the segment index for character i. |
| 191 | */ |
| 192 | function buildCharToSegmentMap(segments: StyledSegment[]): number[] { |
| 193 | const map: number[] = [] |
| 194 | for (let i = 0; i < segments.length; i++) { |
| 195 | const len = segments[i]!.text.length |
| 196 | for (let j = 0; j < len; j++) { |
| 197 | map.push(i) |
| 198 | } |
| 199 | } |
| 200 | return map |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Apply styles to wrapped text by mapping each character back to its original segment. |
no test coverage detected