diff options
author | Dan Davison <dandavison7@gmail.com> | 2022-03-14 15:11:29 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2022-03-14 15:23:28 -0400 |
commit | 6c652ebd433dceeab24eaa1e5c6c378e6628b799 (patch) | |
tree | 90949536cbb1fdf536fc23e0269ae7dfbe103b13 | |
parent | c8cff07f6066ae28bbe3e6e86cf5da95226ffe0a (diff) |
Handle side-by-side differently when assigning line number colors949-line-number-styles
Fixes #949
-rw-r--r-- | src/features/line_numbers.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs index 57cceb61..578f904f 100644 --- a/src/features/line_numbers.rs +++ b/src/features/line_numbers.rs @@ -252,16 +252,12 @@ fn format_and_paint_line_number_field<'a>( let minus_plus_style = match (line_numbers[Minus], line_numbers[Plus]) { (Some(_), None) => styles[Minus], (None, Some(_)) => styles[Plus], + (Some(_), Some(_)) => styles[Plus], // FIXME! _ => unreachable!(), }; let left_right_style = match &config.line_numbers_style_leftright[side] { - style => { - if style.is_omitted { - &minus_plus_style - } else { - style - } - } + style if style.is_omitted => &minus_plus_style, + style => style, }; let mut ansi_strings = Vec::new(); @@ -286,7 +282,14 @@ fn format_and_paint_line_number_field<'a>( None, config, ); - ansi_strings.push(minus_plus_style.paint(formatted)) + // In side-by-side mode we paint an empty cell according to its column; otherwise we + // paint it according to its row. (Only the background color is relevant to an empty + // cell.) See #949 + let style = match (config.side_by_side, line_numbers[Minus].is_some()) { + (true, _) | (false, true) => styles[Minus], + (false, false) => styles[Plus], + }; + ansi_strings.push(style.paint(formatted)) } Some(Placeholder::NumberPlus) => { let formatted = format_line_number( @@ -297,7 +300,14 @@ fn format_and_paint_line_number_field<'a>( Some(plus_file), config, ); - ansi_strings.push(minus_plus_style.paint(formatted)) + // In side-by-side mode we paint an empty cell according to its column; otherwise we + // paint it according to its row. (Only the background color is relevant to an empty + // cell.) See #949 + let style = match (config.side_by_side, line_numbers[Plus].is_some()) { + (true, _) | (false, true) => styles[Plus], + (false, false) => styles[Minus], + }; + ansi_strings.push(style.paint(formatted)) } None => {} _ => unreachable!("Invalid placeholder"), |