replaceAll method

void replaceAll()

Replaces all matches with the text in replaceInputController.

Implementation

void replaceAll() {
  if (_matches.isEmpty) return;

  final text = _codeController.text;
  String pattern = _lastQuery;

  if (!_isRegex) {
    pattern = RegExp.escape(_lastQuery);
  }

  if (_matchWholeWord) {
    pattern = '\\b$pattern\\b';
  }

  try {
    final regExp = RegExp(pattern, caseSensitive: _caseSensitive);
    final newText = text.replaceAll(regExp, replaceInputController.text);

    _codeController.replaceRange(0, text.length, newText);
  } catch (e) {
    debugPrint('FindController: Replace All failed. Error: $e');
  }
}