Handle empty selection box lists in RenderParagraph.assembleSemanticsNode (#67017)
This commit is contained in:
parent
9e715205b7
commit
70973e0214
@ -891,6 +891,7 @@ class RenderParagraph extends RenderBox
|
||||
extentOffset: start + info.text.length,
|
||||
);
|
||||
final List<ui.TextBox> rects = getBoxesForSelection(selection);
|
||||
start += info.text.length;
|
||||
if (rects.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
@ -958,7 +959,6 @@ class RenderParagraph extends RenderBox
|
||||
newChildCache.addLast(newChild);
|
||||
newChildren.add(newChild);
|
||||
}
|
||||
start += info.text.length;
|
||||
}
|
||||
_cachedChildNodes = newChildCache;
|
||||
node.updateWith(config: config, childrenInInversePaintOrder: newChildren);
|
||||
|
@ -16,6 +16,28 @@ import 'rendering_tester.dart';
|
||||
|
||||
const String _kText = "I polished up that handle so carefullee\nThat now I am the Ruler of the Queen's Navee!";
|
||||
|
||||
// A subclass of RenderParagraph that returns an empty list in getBoxesForSelection
|
||||
// for a given TextSelection.
|
||||
// This is intended to simulate SkParagraph's implementation of Paragraph.getBoxesForRange,
|
||||
// which may return an empty list in some situations where Libtxt would return a list
|
||||
// containing an empty box.
|
||||
class RenderParagraphWithEmptySelectionBoxList extends RenderParagraph {
|
||||
RenderParagraphWithEmptySelectionBoxList(InlineSpan text, {
|
||||
TextDirection textDirection,
|
||||
this.emptyListSelection,
|
||||
}) : super(text, textDirection: textDirection);
|
||||
|
||||
TextSelection emptyListSelection;
|
||||
|
||||
@override
|
||||
List<ui.TextBox> getBoxesForSelection(TextSelection selection) {
|
||||
if (selection == emptyListSelection) {
|
||||
return <ui.TextBox>[];
|
||||
}
|
||||
return super.getBoxesForSelection(selection);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('getOffsetForCaret control test', () {
|
||||
final RenderParagraph paragraph = RenderParagraph(
|
||||
@ -546,4 +568,21 @@ void main() {
|
||||
}
|
||||
expect(failed, true);
|
||||
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61020
|
||||
|
||||
test('assembleSemanticsNode handles text spans that do not yield selection boxes', () {
|
||||
final RenderParagraph paragraph = RenderParagraphWithEmptySelectionBoxList(
|
||||
TextSpan(text: '', children: <InlineSpan>[
|
||||
TextSpan(text: 'A', recognizer: TapGestureRecognizer()..onTap = () {}),
|
||||
TextSpan(text: 'B', recognizer: TapGestureRecognizer()..onTap = () {}),
|
||||
TextSpan(text: 'C', recognizer: TapGestureRecognizer()..onTap = () {}),
|
||||
]),
|
||||
textDirection: TextDirection.rtl,
|
||||
emptyListSelection: const TextSelection(baseOffset: 0, extentOffset: 1),
|
||||
);
|
||||
layout(paragraph);
|
||||
|
||||
final SemanticsNode node = SemanticsNode();
|
||||
paragraph.assembleSemanticsNode(node, SemanticsConfiguration(), <SemanticsNode>[]);
|
||||
expect(node.childrenCount, 2);
|
||||
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/61020
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user