lineForPosition method

ResolvedTextLine? lineForPosition(
  1. DiagramTextPosition position
)

At a shared soft-wrap offset, affinity selects the preceding or following visual line. Paragraph separators have distinct offsets and remain distinct.

Implementation

ResolvedTextLine? lineForPosition(DiagramTextPosition position) {
  final matches = lines.where(
    (line) =>
        position.offset >= line.startOffset &&
        position.offset <= line.endOffset,
  );
  if (matches.isEmpty) return lines.isEmpty ? null : lines.last;
  return position.affinity == DiagramTextAffinity.upstream
      ? matches.first
      : matches.last;
}