runAt method
The innermost run whose boxes contain position, or null.
A pure geometric lookup — it does not stand aside for a span that owns its own recognizer, so hover and the pointer cursor still follow the enclosing link across a nested mention. Only handleEvent defers.
Implementation
InlineTapRun? runAt(Offset position, {bool requireHandler = false}) {
if (_inlineTapRuns.isEmpty) {
return null;
}
// One cheap engine call to narrow the field before measuring anything.
// Without it every run is measured on every mouse move, which is a
// getBoxesForSelection per link per pointer event.
final offset = getPositionForOffset(position).offset;
InlineTapRun? best;
for (final run in _inlineTapRuns) {
if (offset < run.start || offset > run.end) {
continue;
}
// A run with nothing to run is not a tap target. Treating it as one lets
// an inert TappableTextSpan nested in a link silently kill the link over
// its own text — innermost wins, and the innermost does nothing.
if (requireHandler && run.onTap == null) {
continue;
}
final boxes = getBoxesForSelection(
TextSelection(baseOffset: run.start, extentOffset: run.end),
boxHeightStyle: ui.BoxHeightStyle.max,
);
for (final box in boxes) {
if (box.toRect().contains(position)) {
if (best == null || run.end - run.start < best.end - best.start) {
best = run;
}
break;
}
}
}
return best;
}