printer: --only-matching works with --replace
When -o/--only-matching is used with -r/--replace, the replacement works as expected. This is not a breaking change because the flags were previously set to conflict.
This commit is contained in:
committed by
Andrew Gallant
parent
363a4fa9b7
commit
f887bc1f86
@@ -316,7 +316,12 @@ impl<W: WriteColor> Printer<W> {
|
||||
let line = {
|
||||
let replacer = CountingReplacer::new(
|
||||
self.replace.as_ref().unwrap(), &mut count, &mut offsets);
|
||||
re.replace_all(&buf[start..end], replacer)
|
||||
if self.only_matching {
|
||||
re.replace_all(
|
||||
&buf[start + match_start..start + match_end], replacer)
|
||||
} else {
|
||||
re.replace_all(&buf[start..end], replacer)
|
||||
}
|
||||
};
|
||||
if self.max_columns.map_or(false, |m| line.len() > m) {
|
||||
let msg = format!(
|
||||
|
||||
Reference in New Issue
Block a user