未验证 提交 6e0e2274 编写于 作者: Y Yegor 提交者: GitHub

fix getBoxesForRange for zero-length ranges (#13483)

上级 bf9d2633
......@@ -201,7 +201,7 @@ class EngineParagraph implements ui.Paragraph {
}) {
assert(boxHeightStyle != null);
assert(boxWidthStyle != null);
if (_plainText == null) {
if (_plainText == null || start == end) {
return <ui.TextBox>[];
}
......
......@@ -96,4 +96,40 @@ void main() async {
paragraph2.layout(ParagraphConstraints(width: fontSize * 5.0));
expect(paragraph2.height, closeTo(fontSize, 0.001)); // because it wraps
});
test('getBoxesForRange returns a box', () {
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(
fontFamily: 'Ahem',
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
fontSize: 10,
textDirection: TextDirection.rtl,
));
builder.addText('abcd');
final Paragraph paragraph = builder.build();
paragraph.layout(const ParagraphConstraints(width: 1000));
expect(
paragraph.getBoxesForRange(1, 2).single,
const TextBox.fromLTRBD(
10,
0,
20,
10,
TextDirection.rtl,
),
);
});
test('getBoxesForRange return empty list for zero-length range', () {
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(
fontFamily: 'Ahem',
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
fontSize: 10,
));
builder.addText('abcd');
final Paragraph paragraph = builder.build();
paragraph.layout(const ParagraphConstraints(width: 1000));
expect(paragraph.getBoxesForRange(0, 0), isEmpty);
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册