safaehCollectPlainTextsAt function

List<String> safaehCollectPlainTextsAt(
  1. BuildContext context,
  2. Offset globalPosition
)

Collects plain RenderParagraph strings under globalPosition.

Implementation

List<String> safaehCollectPlainTextsAt(
  BuildContext context,
  Offset globalPosition,
) {
  final texts = <String>[];
  final renderObject = context.findRenderObject();
  if (renderObject is! RenderObject) return texts;
  void visit(RenderObject node) {
    if (node is RenderParagraph) {
      final box = node;
      if (box.hasSize && box.paintBounds.shift(box.localToGlobal(Offset.zero)).contains(globalPosition)) {
        final text = box.text.toPlainText();
        if (text.trim().isNotEmpty) texts.add(text);
      }
    }
    node.visitChildren(visit);
  }

  visit(renderObject);
  return texts;
}