diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-03-01 22:57:56 -0600 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-03-01 22:57:56 -0600 |
commit | c710571861f8768f12664442e714113fdceb59ad (patch) | |
tree | 6e6cd8798403fecded4875298ddb975d7ae1d5d9 | |
parent | 0c949b20e763a969fd4e8cd0debd032fa12a4fdf (diff) |
Check that first character is + or - before replacing it with space105-svn
-rw-r--r-- | src/delta.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/delta.rs b/src/delta.rs index 80741e64..1e57d544 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -360,7 +360,11 @@ fn prepare(line: &str, tab_width: usize, append_newline: bool) -> String { // The first column contains a -/+/space character, added by git. We skip it here and insert // a replacement space when formatting the line below. - line.next(); + let first_char_replacement = match line.next() { + Some("+") | Some("-") => " ", + Some(c) => c, + None => "", + }; // Expand tabs as spaces. // tab_width = 0 is documented to mean do not replace tabs. @@ -371,7 +375,7 @@ fn prepare(line: &str, tab_width: usize, append_newline: bool) -> String { } else { line.collect::<String>() }; - format!(" {}{}", output_line, terminator) + format!("{}{}{}", first_char_replacement, output_line, terminator) } else { terminator.to_string() } |