Skip to content

Commit 80e1008

Browse files
authored
fix: #110342 unable to update rich text widget gesture recognizer (#116849)
1 parent 76bb8ea commit 80e1008

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

packages/flutter/lib/src/rendering/paragraph.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ class RenderParagraph extends RenderBox
136136
assert(value != null);
137137
switch (_textPainter.text!.compareTo(value)) {
138138
case RenderComparison.identical:
139-
case RenderComparison.metadata:
140139
return;
140+
case RenderComparison.metadata:
141+
_textPainter.text = value;
142+
_cachedCombinedSemanticsInfos = null;
143+
markNeedsSemanticsUpdate();
144+
break;
141145
case RenderComparison.paint:
142146
_textPainter.text = value;
143147
_cachedAttributedLabel = null;

packages/flutter/test/rendering/paragraph_test.dart

+48
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,54 @@ void main() {
12991299
expect(selection.end, 31);
13001300
});
13011301
});
1302+
1303+
test('can just update the gesture recognizer', () async {
1304+
final TapGestureRecognizer recognizerBefore = TapGestureRecognizer()..onTap = () {};
1305+
final RenderParagraph paragraph = RenderParagraph(
1306+
TextSpan(text: 'How are you \n', recognizer: recognizerBefore),
1307+
textDirection: TextDirection.ltr,
1308+
);
1309+
1310+
int semanticsUpdateCount = 0;
1311+
TestRenderingFlutterBinding.instance.pipelineOwner.ensureSemantics(
1312+
listener: () {
1313+
++semanticsUpdateCount;
1314+
},
1315+
);
1316+
1317+
layout(paragraph);
1318+
1319+
expect((paragraph.text as TextSpan).recognizer, same(recognizerBefore));
1320+
final SemanticsNode nodeBefore = SemanticsNode();
1321+
paragraph.assembleSemanticsNode(nodeBefore, SemanticsConfiguration(), <SemanticsNode>[]);
1322+
expect(semanticsUpdateCount, 0);
1323+
List<SemanticsNode> children = <SemanticsNode>[];
1324+
nodeBefore.visitChildren((SemanticsNode child) {
1325+
children.add(child);
1326+
return true;
1327+
});
1328+
SemanticsData data = children.single.getSemanticsData();
1329+
expect(data.hasAction(SemanticsAction.longPress), false);
1330+
expect(data.hasAction(SemanticsAction.tap), true);
1331+
1332+
final LongPressGestureRecognizer recognizerAfter = LongPressGestureRecognizer()..onLongPress = () {};
1333+
paragraph.text = TextSpan(text: 'How are you \n', recognizer: recognizerAfter);
1334+
1335+
pumpFrame(phase: EnginePhase.flushSemantics);
1336+
1337+
expect((paragraph.text as TextSpan).recognizer, same(recognizerAfter));
1338+
final SemanticsNode nodeAfter = SemanticsNode();
1339+
paragraph.assembleSemanticsNode(nodeAfter, SemanticsConfiguration(), <SemanticsNode>[]);
1340+
expect(semanticsUpdateCount, 1);
1341+
children = <SemanticsNode>[];
1342+
nodeAfter.visitChildren((SemanticsNode child) {
1343+
children.add(child);
1344+
return true;
1345+
});
1346+
data = children.single.getSemanticsData();
1347+
expect(data.hasAction(SemanticsAction.longPress), true);
1348+
expect(data.hasAction(SemanticsAction.tap), false);
1349+
});
13021350
}
13031351

13041352
class MockCanvas extends Fake implements Canvas {

0 commit comments

Comments
 (0)