diff --git a/src/ansi/mod.rs b/src/ansi/mod.rs index 9e26082c9..859acafbf 100644 --- a/src/ansi/mod.rs +++ b/src/ansi/mod.rs @@ -242,6 +242,11 @@ mod tests { assert_eq!(measure_text_width("a\nb\n"), 2); } + #[test] + fn test_measure_text_width_ignores_bom() { + assert_eq!(measure_text_width("a\u{feff}b"), 2); + } + #[test] fn test_strip_ansi_codes_osc_hyperlink() { assert_eq!(strip_ansi_codes("\x1b[38;5;4m\x1b]8;;file:///Users/dan/src/delta/src/ansi/mod.rs\x1b\\src/ansi/mod.rs\x1b]8;;\x1b\\\x1b[0m\n"), diff --git a/src/delta.rs b/src/delta.rs index 5464df9a6..8108c5961 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -205,7 +205,7 @@ impl<'a> StateMachine<'a> { } fn ingest_line_utf8(&mut self, raw_line: String) { - self.raw_line = raw_line; + self.raw_line = raw_line.replace('\u{feff}', ""); // When a file has \r\n line endings, git sometimes adds ANSI escape sequences between the // \r and \n, in which case byte_lines does not remove the \r. Remove it now. [EndCRLF] // TODO: Limit the number of characters we examine when looking for the \r? diff --git a/src/options/set.rs b/src/options/set.rs index 6d26d15df..0bfff8a4e 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -388,9 +388,6 @@ fn gather_features( if opt.hyperlinks { gather_builtin_features_recursively("hyperlinks", &mut features, builtin_features, opt); } - if opt.line_numbers { - gather_builtin_features_recursively("line-numbers", &mut features, builtin_features, opt); - } if opt.navigate { gather_builtin_features_recursively("navigate", &mut features, builtin_features, opt); } @@ -423,6 +420,12 @@ fn gather_features( ); } + // Gather `line-numbers` after theme features so theme-provided line-number styles are not + // overridden by the built-in default styles when `--line-numbers` is enabled. + if opt.line_numbers { + gather_builtin_features_recursively("line-numbers", &mut features, builtin_features, opt); + } + Vec::::from(features) } @@ -828,6 +831,37 @@ pub mod tests { remove_file(git_config_path).unwrap(); } + #[test] + fn test_line_numbers_flag_does_not_override_theme_line_number_styles() { + let git_config_contents = b" +[delta] + features = catppuccin-latte + +[delta \"catppuccin-latte\"] + line-numbers-left-style = red + line-numbers-minus-style = yellow + line-numbers-zero-style = green + line-numbers-plus-style = blue + line-numbers-right-style = magenta +"; + let git_config_path = + "delta__test_line_numbers_flag_does_not_override_theme_line_number_styles.gitconfig"; + + let opt = integration_test_utils::make_options_from_args_and_git_config( + &["--line-numbers"], + Some(git_config_contents), + Some(git_config_path), + ); + + assert_eq!(opt.line_numbers_left_style, "red"); + assert_eq!(opt.line_numbers_minus_style, "yellow"); + assert_eq!(opt.line_numbers_zero_style, "green"); + assert_eq!(opt.line_numbers_plus_style, "blue"); + assert_eq!(opt.line_numbers_right_style, "magenta"); + + remove_file(git_config_path).unwrap(); + } + #[test] fn test_parse_width_specifier() { use super::parse_width_specifier; diff --git a/src/tests/integration_test_utils.rs b/src/tests/integration_test_utils.rs index 1b2f1dfc1..f0ebf7036 100644 --- a/src/tests/integration_test_utils.rs +++ b/src/tests/integration_test_utils.rs @@ -418,4 +418,20 @@ ignored! 2 (green)+2(normal)", ); } + + #[test] + fn test_delta_test_ignores_bom_in_raw_output_with_line_numbers() { + let input = "@@ -1,1 +1,1 @@ fn foo() {\n-\u{feff}abc\n+\u{feff}abd\n"; + DeltaTest::with_args(&["--raw"]) + .set_config(|c| c.pager = None) + .set_config(|c| c.line_numbers = true) + .with_input(input) + .expect( + r#" + #indent_mark + @@ -1,1 +1,1 @@ fn foo() { + 1 ⋮ │-abc + ⋮ 1 │+abd"#, + ); + } }