Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
fix: #110342 unable to update rich text widget gesture recognizer (#1…
Browse files Browse the repository at this point in the history
…16849)
  • Loading branch information
LucasXu0 authored Dec 16, 2022
1 parent 76bb8ea commit 80e1008
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/flutter/lib/src/rendering/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 48 additions & 0 deletions packages/flutter/test/rendering/paragraph_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 80e1008

Please sign in to comment.