aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2020-07-25 23:52:52 +0200
committerTeddy Wing2020-07-25 23:52:52 +0200
commit0ea9202eb81e18647b40563fd3dbc61b626ce2ec (patch)
treef779468bdc643f66e074805041d2905df76f4fc9 /src
parent74210fa2fd90c5b7cae91f7ea6f4e1f64a597198 (diff)
downloadgit-suggestion-0ea9202eb81e18647b40563fd3dbc61b626ce2ec.tar.bz2
Suggestion.apply_to(): Use correct line numbers
We had been using the enumerator's index, which starts at 0, but line numbers start at 1. Use the correct line number.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7108395..a743161 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -145,13 +145,15 @@ impl Suggestion {
let reader = BufReader::new(original);
for (i, line) in reader.lines().enumerate() {
+ let line_number = i + 1;
+
match line {
Ok(l) => {
- if i == self.original_end_line {
+ if line_number == self.original_end_line {
write!(writer, "{}", self.suggestion()).unwrap();
} else if self.original_start_line.is_none()
- || i < self.original_start_line.unwrap()
- || i > self.original_end_line {
+ || line_number < self.original_start_line.unwrap()
+ || line_number > self.original_end_line {
writeln!(writer, "{}", l).unwrap();
}
},