protected override void WriteEndReplacement(Match match, string result) { if (IsInteractive && result.IndexOfAny(_newLineChars) == -1) { string?newResult = ConsoleHelpers.ReadUserInput("Replacement: ", result, Options.Indent); if (newResult == null) { return; } result = newResult; } if (_lazyWriter != null) { if (IsInteractive || ConsoleHelpers.AskToExecute("Replace?", Options.Indent)) { _lazyWriter.Value.Write(Input.AsSpan(_writerIndex, match.Index - _writerIndex)); _lazyWriter.Value.Write(result); _writerIndex = match.Index + match.Length; ReplacementCount++; } } else if (!ContinueWithoutAsking && !IsInteractive && ConsoleHelpers.AskToContinue(Options.Indent) == DialogResult.YesToAll) { ContinueWithoutAsking = true; } }
protected override void WriteEndReplacement(ICapture capture, string?result) { bool isUserInput = IsInteractive && (capture is RegexCapture || result == null) && (result == null || result.IndexOfAny(_newLineChars) == -1); string replacement = result ?? capture.Value; if (isUserInput) { replacement = ConsoleHelpers.ReadUserInput(replacement, Options.Indent + "Replacement: "); } if (!string.Equals(capture.Value, replacement, StringComparison.Ordinal)) { if (_lazyWriter != null) { if (IsInteractive || ConsoleHelpers.AskToExecute("Replace?", Options.Indent)) { _lazyWriter.Value.Write(Input.AsSpan(_writerIndex, capture.Index - _writerIndex)); _lazyWriter.Value.Write(replacement); _writerIndex = capture.Index + capture.Length; ReplacementCount++; } } else if (!ContinueWithoutAsking && !IsInteractive && ConsoleHelpers.AskToContinue(Options.Indent) == DialogResult.YesToAll) { ContinueWithoutAsking = true; } } SpellcheckState?.ProcessReplacement( Input, capture, replacement, lineNumber: (ValueWriter as LineNumberValueWriter)?.LineNumber, isUserInput: true); }