File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -1468,10 +1468,15 @@ class TextPainter {
1468
1468
final _LineCaretMetrics metrics;
1469
1469
final List <TextBox > boxes = cachedLayout.paragraph
1470
1470
.getBoxesForRange (graphemeRange.start, graphemeRange.end, boxHeightStyle: ui.BoxHeightStyle .strut);
1471
+
1471
1472
if (boxes.isNotEmpty) {
1472
- final TextBox box = boxes.single;
1473
+ final bool ahchorToLeft = switch (glyphInfo.writingDirection) {
1474
+ TextDirection .ltr => anchorToLeadingEdge,
1475
+ TextDirection .rtl => ! anchorToLeadingEdge,
1476
+ };
1477
+ final TextBox box = ahchorToLeft ? boxes.first : boxes.last;
1473
1478
metrics = _LineCaretMetrics (
1474
- offset: Offset (anchorToLeadingEdge ? box.start : box.end , box.top),
1479
+ offset: Offset (ahchorToLeft ? box.left : box.right , box.top),
1475
1480
writingDirection: box.direction,
1476
1481
);
1477
1482
} else {
Original file line number Diff line number Diff line change @@ -1682,6 +1682,20 @@ void main() {
1682
1682
});
1683
1683
}, skip: kIsWeb && ! isSkiaWeb); // [intended] strut spport for HTML renderer https://github.com/flutter/flutter/issues/32243.
1684
1684
1685
+ test ('getOffsetForCaret does not crash on decomposed characters' , () {
1686
+ final TextPainter painter = TextPainter (
1687
+ textDirection: TextDirection .ltr,
1688
+ text: const TextSpan (
1689
+ text: '각' ,
1690
+ style: TextStyle (fontSize: 10 ),
1691
+ ),
1692
+ )..layout (maxWidth: 1 ); // Force the jamo characters to soft wrap.
1693
+ expect (
1694
+ () => painter.getOffsetForCaret (const TextPosition (offset: 0 ), Rect .zero),
1695
+ returnsNormally,
1696
+ );
1697
+ });
1698
+
1685
1699
test ('TextPainter dispatches memory events' , () async {
1686
1700
await expectLater (
1687
1701
await memoryEvents (() => TextPainter ().dispose (), TextPainter ),
You can’t perform that action at this time.
0 commit comments