RenderTextSource class
A single piece of painted text discovered by findRenderTextSources, with enough of its own RenderObject exposed to compute word-level highlight geometry without this file needing to know whether the underlying widget was a Text, a RichText, or an EditableText.
Why this exists at all
A SemanticsNode (what walkSemantics in semantics_walker.dart finds
matches against) has no public path back to the RenderObject that
produced it — that mapping simply isn't exposed by the framework outside
of a debug-only accessor (see the example find-in-page spike's
_findBarSubtreeId doc, in
example/lib/src/sections/find_in_page/find_spike.dart, for the one place
that spike does rely on that debug accessor, and why it is an accepted
spike-only limitation there).
Rather than trying to resolve "this semantics match's exact
RenderObject", this walks the render tree directly — independently
of semantics entirely — collecting every RenderParagraph (backing
Text and RichText) and RenderEditable (backing EditableText) it
finds, each already carrying both the text it painted and the geometry
to compute per-character boxes from (RenderParagraph.getBoxesForSelection
/ RenderEditable.getBoxesForSelection). A caller then correlates one of
these against a given FindMatch.globalRect by simple rect containment
(see findAllTextOccurrences callers in the example find-in-page spike's
find_spike.dart, at example/lib/src/sections/find_in_page/) — geometry
is a far more stable correlation key here than any node-identity scheme would
be, since a Text/RichText's own Semantics wrapper paints at exactly
the same box as the RenderParagraph beneath it (no intervening padding),
and an unscrolled, single-line EditableText's RenderEditable does the
same relative to its own Semantics node.
This is intentionally not wired into every match — see the example
find-in-page spike's build() (in
example/lib/src/sections/find_in_page/find_spike.dart) for why only the
currently-visible matches are ever resolved against this list:
getBoxesForSelection is
real per-glyph layout work, and paying it for dozens of scrolled-away
matches on every frame would be wasted cost for boxes nobody can see
anyway.
- Annotations
Constructors
-
RenderTextSource({required String plainText, required Rect globalRect, required List<
Rect> boxesForSelection(TextSelection selection), required RenderObject renderObject}) -
Creates a RenderTextSource.
const
Properties
-
boxesForSelection
→ List<
Rect> Function(TextSelection selection) -
Returns the global-space rectangles covering
selectionwithin this source's painted text — one per visually-distinct run (a wrapped word spans two boxes; a bidirectional boundary can too).final - globalRect → Rect
-
This render object's bounding box in the same global (screen-origin)
coordinate space
walkSemanticscomputes FindMatch.globalRect in — see RenderObject.getTransformTo (called with anulltarget) for why the two coordinate spaces coincide.final - hashCode → int
-
The hash code for this object.
no setterinherited
- plainText → String
-
The exact text this render object painted, suitable for locating query
occurrences at the same character offsets boxesForSelection expects.
final
- renderObject → RenderObject
-
The underlying RenderParagraph or RenderEditable this source was
built from.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited