replaceAllMatches method

void replaceAllMatches(
  1. String replaceText
)

Replaces all the found occurrences of pattern with replaceText

Implementation

void replaceAllMatches(String replaceText) {
  if (replaceText.isEmpty ||
      queriedPattern.isEmpty ||
      matchWrappers.value.isEmpty) {
    return;
  }

  // _highlightAllMatches(queriedPattern.length, unHighlight: true);
  for (final matchWrap in matchWrappers.value.reversed) {
    final node = editorState.getNodeAtPath(matchWrap.path)!;
    final String replaced;
    if (regex) {
      replaced = _getRegexReplaced(replaceText, matchWrap.match);
    } else {
      replaced = replaceText;
    }

    final transaction = editorState.transaction
      ..replaceText(
        node,
        matchWrap.selection.startIndex,
        matchWrap.selection.length,
        replaced,
      );

    editorState.apply(transaction);
  }
  matchWrappers.value.clear();
}