Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6e0e227

Browse files
authored
fix getBoxesForRange for zero-length ranges (#13483)
1 parent bf9d263 commit 6e0e227

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/web_ui/lib/src/engine/text/paragraph.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class EngineParagraph implements ui.Paragraph {
201201
}) {
202202
assert(boxHeightStyle != null);
203203
assert(boxWidthStyle != null);
204-
if (_plainText == null) {
204+
if (_plainText == null || start == end) {
205205
return <ui.TextBox>[];
206206
}
207207

lib/web_ui/test/paragraph_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,40 @@ void main() async {
9696
paragraph2.layout(ParagraphConstraints(width: fontSize * 5.0));
9797
expect(paragraph2.height, closeTo(fontSize, 0.001)); // because it wraps
9898
});
99+
100+
test('getBoxesForRange returns a box', () {
101+
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(
102+
fontFamily: 'Ahem',
103+
fontStyle: FontStyle.normal,
104+
fontWeight: FontWeight.normal,
105+
fontSize: 10,
106+
textDirection: TextDirection.rtl,
107+
));
108+
builder.addText('abcd');
109+
final Paragraph paragraph = builder.build();
110+
paragraph.layout(const ParagraphConstraints(width: 1000));
111+
expect(
112+
paragraph.getBoxesForRange(1, 2).single,
113+
const TextBox.fromLTRBD(
114+
10,
115+
0,
116+
20,
117+
10,
118+
TextDirection.rtl,
119+
),
120+
);
121+
});
122+
123+
test('getBoxesForRange return empty list for zero-length range', () {
124+
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(
125+
fontFamily: 'Ahem',
126+
fontStyle: FontStyle.normal,
127+
fontWeight: FontWeight.normal,
128+
fontSize: 10,
129+
));
130+
builder.addText('abcd');
131+
final Paragraph paragraph = builder.build();
132+
paragraph.layout(const ParagraphConstraints(width: 1000));
133+
expect(paragraph.getBoxesForRange(0, 0), isEmpty);
134+
});
99135
}

0 commit comments

Comments
 (0)