Unverified Commit 80e1008c authored by Lucas.Xu's avatar Lucas.Xu Committed by GitHub

fix: #110342 unable to update rich text widget gesture recognizer (#116849)

parent 76bb8ead
......@@ -136,8 +136,12 @@ class RenderParagraph extends RenderBox
assert(value != null);
switch (_textPainter.text!.compareTo(value)) {
case RenderComparison.identical:
case RenderComparison.metadata:
return;
case RenderComparison.metadata:
_textPainter.text = value;
_cachedCombinedSemanticsInfos = null;
markNeedsSemanticsUpdate();
break;
case RenderComparison.paint:
_textPainter.text = value;
_cachedAttributedLabel = null;
......
......@@ -1299,6 +1299,54 @@ void main() {
expect(selection.end, 31);
});
});
test('can just update the gesture recognizer', () async {
final TapGestureRecognizer recognizerBefore = TapGestureRecognizer()..onTap = () {};
final RenderParagraph paragraph = RenderParagraph(
TextSpan(text: 'How are you \n', recognizer: recognizerBefore),
textDirection: TextDirection.ltr,
);
int semanticsUpdateCount = 0;
TestRenderingFlutterBinding.instance.pipelineOwner.ensureSemantics(
listener: () {
++semanticsUpdateCount;
},
);
layout(paragraph);
expect((paragraph.text as TextSpan).recognizer, same(recognizerBefore));
final SemanticsNode nodeBefore = SemanticsNode();
paragraph.assembleSemanticsNode(nodeBefore, SemanticsConfiguration(), <SemanticsNode>[]);
expect(semanticsUpdateCount, 0);
List<SemanticsNode> children = <SemanticsNode>[];
nodeBefore.visitChildren((SemanticsNode child) {
children.add(child);
return true;
});
SemanticsData data = children.single.getSemanticsData();
expect(data.hasAction(SemanticsAction.longPress), false);
expect(data.hasAction(SemanticsAction.tap), true);
final LongPressGestureRecognizer recognizerAfter = LongPressGestureRecognizer()..onLongPress = () {};
paragraph.text = TextSpan(text: 'How are you \n', recognizer: recognizerAfter);
pumpFrame(phase: EnginePhase.flushSemantics);
expect((paragraph.text as TextSpan).recognizer, same(recognizerAfter));
final SemanticsNode nodeAfter = SemanticsNode();
paragraph.assembleSemanticsNode(nodeAfter, SemanticsConfiguration(), <SemanticsNode>[]);
expect(semanticsUpdateCount, 1);
children = <SemanticsNode>[];
nodeAfter.visitChildren((SemanticsNode child) {
children.add(child);
return true;
});
data = children.single.getSemanticsData();
expect(data.hasAction(SemanticsAction.longPress), true);
expect(data.hasAction(SemanticsAction.tap), false);
});
}
class MockCanvas extends Fake implements Canvas {
......
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