Skip to content

Commit e5c7dd4

Browse files
PR updates
1 parent ce0d3ed commit e5c7dd4

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

super_editor/lib/src/infrastructure/attributed_text_styles.dart

+10-13
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,26 @@ extension ComputeTextSpan on AttributedText {
4040

4141
// A single span might be divided in multiple inline spans if there are placeholders.
4242
// Keep track of the start of the current inline span.
43-
int startOfInlineSpan = span.start;
43+
int startOfMostRecentTextRun = span.start;
4444

4545
// 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) {
4948
// We found a placeholder. Build a widget for it.
5049

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.
5352
inlineSpans.add(
5453
TextSpan(
55-
text: substring(startOfInlineSpan, characterIndex),
54+
text: substring(startOfMostRecentTextRun, i),
5655
style: textStyle,
5756
),
5857
);
5958
}
6059

6160
Widget? inlineWidget;
6261
for (final builder in inlineWidgetBuilders) {
63-
inlineWidget = builder(context, textStyle, placeholders[characterIndex]!);
62+
inlineWidget = builder(context, textStyle, placeholders[i]!);
6463
if (inlineWidget != null) {
6564
break;
6665
}
@@ -76,17 +75,15 @@ extension ComputeTextSpan on AttributedText {
7675
}
7776

7877
// Start another inline span after the placeholder.
79-
startOfInlineSpan = characterIndex + 1;
78+
startOfMostRecentTextRun = i + 1;
8079
}
81-
82-
characterIndex += 1;
8380
}
8481

85-
if (startOfInlineSpan <= span.end) {
82+
if (startOfMostRecentTextRun <= span.end) {
8683
// There is text after the last placeholder or there is no placeholder at all.
8784
inlineSpans.add(
8885
TextSpan(
89-
text: substring(startOfInlineSpan, span.end + 1),
86+
text: substring(startOfMostRecentTextRun, span.end + 1),
9087
style: textStyle,
9188
),
9289
);

0 commit comments

Comments
 (0)