summaryrefslogtreecommitdiffstats
path: root/src/delta.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-06-16 10:18:24 -0400
committerDan Davison <dandavison7@gmail.com>2020-06-17 09:03:38 -0400
commit5d5b4a3995e109b24b420daa094773ac4e6dc5bf (patch)
tree9742c993efdbd75fa6316d683975fa81a36bd206 /src/delta.rs
parent47f963639aa5ee3e7d4b82ab846878350ef5999b (diff)
Eliminate leading space unless --keep-plus-minus-markers
Diffstat (limited to 'src/delta.rs')
-rw-r--r--src/delta.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/delta.rs b/src/delta.rs
index b498bd0a..36ea6a56 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -467,7 +467,11 @@ fn handle_hunk_line(
}
Some(' ') => {
let state = State::HunkZero;
- let prefix = if line.is_empty() { "" } else { &line[..1] };
+ let prefix = if config.keep_plus_minus_markers && !line.is_empty() {
+ &line[..1]
+ } else {
+ ""
+ };
painter.paint_buffered_lines();
let lines = vec![prepare(&line, true, config)];
let syntax_style_sections = Painter::get_syntax_style_sections_for_lines(
@@ -520,12 +524,22 @@ fn prepare(line: &str, append_newline: bool, config: &Config) -> String {
if !line.is_empty() {
let mut line = line.graphemes(true);
- // The first column contains a -/+/space character, added by git. We substitute it for a
- // space now, so that it is not present during syntax highlighting, and substitute again
- // when emitting the line.
+ // The first column contains a -/+/space character, added by git. If we are retaining them
+ // (--keep-plus-minus-markers), then we substitute it for a space now, so that it is not
+ // present during syntax highlighting, and reinstate it when emitting the line in
+ // Painter::paint_lines. If we not retaining them, then we drop it now, and
+ // Painter::paint_lines doesn't inject anything.
line.next();
-
- format!(" {}{}", expand_tabs(line, config.tab_width), terminator)
+ format!(
+ "{}{}{}",
+ if config.keep_plus_minus_markers {
+ " "
+ } else {
+ ""
+ },
+ expand_tabs(line, config.tab_width),
+ terminator
+ )
} else {
terminator.to_string()
}