Skip to content

Commit c99e312

Browse files
#5756 Improved tapping on links when the font is really small.
1 parent d5849d1 commit c99e312

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/src/render_paragraph.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -509,23 +509,36 @@ class ClickableRenderParagraph extends RenderBox
509509
return true;
510510
}
511511
bool hit = hitTestInlineChildren(result, position);
512-
if (hit && wasHit(result)) {
512+
if (hit && _wasHit(result)) {
513513
return true;
514514
}
515515

516+
if (_hasClickableParagraphParent()) {
517+
return false;
518+
}
519+
516520
if (preferredLineHeight >= 24) return false;
517521
final hitTryOffset = math.min(24 - _textPainter.preferredLineHeight, preferredLineHeight / 2);
518-
final dec = Offset(position.dx, position.dy + hitTryOffset);
519-
hit = (hitTestInlineChildren(result, dec));
522+
final above = Offset(position.dx, position.dy + hitTryOffset);
523+
hit = (hitTestInlineChildren(result, above));
520524
if (hit && result.path.any((entry) => entry is TextSpan)) {
521525
return true;
522526
}
523527

524-
final inc = Offset(position.dx, position.dy - hitTryOffset);
525-
return hitTestInlineChildren(result, inc);
528+
final below = Offset(position.dx, position.dy - hitTryOffset);
529+
return hitTestInlineChildren(result, below);
526530
}
527531

528-
bool wasHit(HitTestResult result) => result.path.any((entry) => entry.target is TextSpan);
532+
bool _wasHit(HitTestResult result) => result.path.any((entry) => entry.target is TextSpan);
533+
534+
bool _hasClickableParagraphParent() {
535+
var p = parent;
536+
while (p != null) {
537+
if (p is ClickableRenderParagraph) return true;
538+
p = p.parent;
539+
}
540+
return false;
541+
}
529542

530543
bool _needsClipping = false;
531544
ui.Shader? _overflowShader;
@@ -2911,7 +2924,3 @@ class _SelectableFragment with Selectable, Diagnosticable, ChangeNotifier implem
29112924
properties.add(DiagnosticsProperty<String>('fullText', fullText));
29122925
}
29132926
}
2914-
2915-
class ExtraOffset extends Offset {
2916-
ExtraOffset(super.dx, super.dy);
2917-
}

0 commit comments

Comments
 (0)