@@ -40,27 +40,26 @@ extension ComputeTextSpan on AttributedText {
40
40
41
41
// A single span might be divided in multiple inline spans if there are placeholders.
42
42
// Keep track of the start of the current inline span.
43
- int startOfInlineSpan = span.start;
43
+ int startOfMostRecentTextRun = span.start;
44
44
45
45
// Look for placeholders within the current span and split the span accordingly.
46
- int characterIndex = span.start;
47
- while (characterIndex <= span.end) {
48
- if (placeholders[characterIndex] != null ) {
46
+ for (int i = span.start; i <= span.end; i++ ) {
47
+ if (placeholders[i] != null ) {
49
48
// We found a placeholder. Build a widget for it.
50
49
51
- if (characterIndex > startOfInlineSpan ) {
52
- // There is text before the placeholder.
50
+ if (i > startOfMostRecentTextRun ) {
51
+ // There is text before the placeholder. Add the current text run to the span.
53
52
inlineSpans.add (
54
53
TextSpan (
55
- text: substring (startOfInlineSpan, characterIndex ),
54
+ text: substring (startOfMostRecentTextRun, i ),
56
55
style: textStyle,
57
56
),
58
57
);
59
58
}
60
59
61
60
Widget ? inlineWidget;
62
61
for (final builder in inlineWidgetBuilders) {
63
- inlineWidget = builder (context, textStyle, placeholders[characterIndex ]! );
62
+ inlineWidget = builder (context, textStyle, placeholders[i ]! );
64
63
if (inlineWidget != null ) {
65
64
break ;
66
65
}
@@ -76,17 +75,15 @@ extension ComputeTextSpan on AttributedText {
76
75
}
77
76
78
77
// Start another inline span after the placeholder.
79
- startOfInlineSpan = characterIndex + 1 ;
78
+ startOfMostRecentTextRun = i + 1 ;
80
79
}
81
-
82
- characterIndex += 1 ;
83
80
}
84
81
85
- if (startOfInlineSpan <= span.end) {
82
+ if (startOfMostRecentTextRun <= span.end) {
86
83
// There is text after the last placeholder or there is no placeholder at all.
87
84
inlineSpans.add (
88
85
TextSpan (
89
- text: substring (startOfInlineSpan , span.end + 1 ),
86
+ text: substring (startOfMostRecentTextRun , span.end + 1 ),
90
87
style: textStyle,
91
88
),
92
89
);
0 commit comments