mirror of
https://github.com/flutter/flutter
synced 2024-08-24 18:36:03 +00:00
Fix getOffsetForCaret
crash (#146669)
Fixes a crash in Google tests (b/333560406) related to a decomposed complex character.
This commit is contained in:
parent
65e8ec2140
commit
7db26b09bb
|
@ -1468,10 +1468,15 @@ class TextPainter {
|
|||
final _LineCaretMetrics metrics;
|
||||
final List<TextBox> boxes = cachedLayout.paragraph
|
||||
.getBoxesForRange(graphemeRange.start, graphemeRange.end, boxHeightStyle: ui.BoxHeightStyle.strut);
|
||||
|
||||
if (boxes.isNotEmpty) {
|
||||
final TextBox box = boxes.single;
|
||||
final bool ahchorToLeft = switch (glyphInfo.writingDirection) {
|
||||
TextDirection.ltr => anchorToLeadingEdge,
|
||||
TextDirection.rtl => !anchorToLeadingEdge,
|
||||
};
|
||||
final TextBox box = ahchorToLeft ? boxes.first : boxes.last;
|
||||
metrics = _LineCaretMetrics(
|
||||
offset: Offset(anchorToLeadingEdge ? box.start : box.end, box.top),
|
||||
offset: Offset(ahchorToLeft ? box.left : box.right, box.top),
|
||||
writingDirection: box.direction,
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -1682,6 +1682,20 @@ void main() {
|
|||
});
|
||||
}, skip: kIsWeb && !isSkiaWeb); // [intended] strut spport for HTML renderer https://github.com/flutter/flutter/issues/32243.
|
||||
|
||||
test('getOffsetForCaret does not crash on decomposed characters', () {
|
||||
final TextPainter painter = TextPainter(
|
||||
textDirection: TextDirection.ltr,
|
||||
text: const TextSpan(
|
||||
text: '각',
|
||||
style: TextStyle(fontSize: 10),
|
||||
),
|
||||
)..layout(maxWidth: 1); // Force the jamo characters to soft wrap.
|
||||
expect(
|
||||
() => painter.getOffsetForCaret(const TextPosition(offset: 0), Rect.zero),
|
||||
returnsNormally,
|
||||
);
|
||||
});
|
||||
|
||||
test('TextPainter dispatches memory events', () async {
|
||||
await expectLater(
|
||||
await memoryEvents(() => TextPainter().dispose(), TextPainter),
|
||||
|
|
Loading…
Reference in a new issue