replaceAllSearchMatches method

bool replaceAllSearchMatches(
  1. String replacementTemplate
)

Replaces all current matches as one undoable edit.

Implementation

bool replaceAllSearchMatches(String replacementTemplate) {
  final session = _searchSession;
  if (session == null || session.matches.isEmpty) return false;
  final graphemes = _document.flattenWithNewlines();
  final replaced = replaceTextSearchMatches(
    graphemes,
    session.matches,
    (match) => uni
        .graphemes(
          expandSearchReplacementTemplate(
            replacementTemplate,
            match,
            match.groups.isEmpty ? '' : match.groups.first ?? '',
          ),
        )
        .toList(growable: false),
  );
  setText(replaced.join());
  startSearch(session.query);
  return true;
}