Unverified Commit 5736def3 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Handle selection ranges where getBoxesForSelection returns an empty list (#59014)

parent 22ea668f
......@@ -1462,13 +1462,15 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
final Offset paintOffset = _paintOffset;
if (selection.isCollapsed) {
final List<ui.TextBox> boxes = selection.isCollapsed ?
<ui.TextBox>[] : _textPainter.getBoxesForSelection(selection);
if (boxes.isEmpty) {
// TODO(mpcomplete): This doesn't work well at an RTL/LTR boundary.
final Offset caretOffset = _textPainter.getOffsetForCaret(selection.extent, _caretPrototype);
final Offset start = Offset(0.0, preferredLineHeight) + caretOffset + paintOffset;
return <TextSelectionPoint>[TextSelectionPoint(start, null)];
} else {
final List<ui.TextBox> boxes = _textPainter.getBoxesForSelection(selection);
final Offset start = Offset(boxes.first.start, boxes.first.bottom) + paintOffset;
final Offset end = Offset(boxes.last.end, boxes.last.bottom) + paintOffset;
return <TextSelectionPoint>[
......
......@@ -796,4 +796,23 @@ void main() {
await simulateKeyUpEvent(LogicalKeyboardKey.delete, platform: 'android');
expect(delegate.textEditingValue.text, '');
}, skip: kIsWeb); // Key simulation doesn't work on web.
test('getEndpointsForSelection handles empty characters', () {
final TextSelectionDelegate delegate = FakeEditableTextState();
final RenderEditable editable = RenderEditable(
// This is a Unicode left-to-right mark character that will not render
// any glyphs.
text: const TextSpan(text: '\u200e'),
textAlign: TextAlign.start,
textDirection: TextDirection.ltr,
offset: ViewportOffset.zero(),
textSelectionDelegate: delegate,
startHandleLayerLink: LayerLink(),
endHandleLayerLink: LayerLink(),
);
editable.layout(BoxConstraints.loose(const Size(100, 100)));
final List<TextSelectionPoint> endpoints = editable.getEndpointsForSelection(
const TextSelection(baseOffset: 0, extentOffset: 1));
expect(endpoints[0].point.dx, 0);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment