Skip to content

Commit

Permalink
fix copy operation to account for wrapped lines
Browse files Browse the repository at this point in the history
  • Loading branch information
little-dude committed Jun 8, 2019
1 parent 9e87633 commit af850cd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@ impl<'a, 'b, 'c> UpdateHelper<'a, 'b, 'c> {

// we'll only apply the copy if there actually are valid lines to copy
if nb_valid_lines > 0 {
let old_first_line_num = old_lines[0].line_num.unwrap(); // valid lines always have a line number, so it's fine to unwrap.

// the line_num_updater is the function that will update the line numbers if necessary
let diff = if let Some(new_first_line_num) = first_line_num {
new_first_line_num as i64 - old_first_line_num as i64
// find the first "real" line (ie non-wrapped), and
// compute the difference between its line number and
// its *new* line number, given by the "copy"
// operation. This will be used to update the line
// number for all the lines we copy.
old_lines.iter().find_map(|line| {
line.line_num.map(|num| new_first_line_num as i64 - num as i64)
}).unwrap_or(0)
} else {
// if the "copy" operation does not specify a new line
// number, just set the diff to 0
0
};

Expand Down

0 comments on commit af850cd

Please sign in to comment.