selectSearchMatch method

bool selectSearchMatch({
  1. required bool forward,
  2. bool wrap = true,
})

Selects the next or previous search match.

Implementation

bool selectSearchMatch({required bool forward, bool wrap = true}) {
  final session = _searchSession;
  if (session == null) return false;
  final match = forward
      ? session.next(wrap: wrap)
      : session.previous(wrap: wrap);
  if (match == null) return false;
  setSelections(
    TextSelectionSet([
      TextSelectionRange(
        startOffset: match.startOffset,
        endOffset: match.endOffset,
      ),
    ], primaryOffset: match.endOffset),
  );
  setHighlights(
    session.matches.map(
      (candidate) => TextHighlightRange(
        startOffset: candidate.startOffset,
        endOffset: candidate.endOffset,
      ),
    ),
    activeIndex: session.index,
  );
  return true;
}