diff options
author | Dan Davison <dandavison7@gmail.com> | 2021-08-20 18:34:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-20 18:34:50 -0700 |
commit | 130b0b6a2146d4b42be6f8cfeda4d120e65576f2 (patch) | |
tree | e61443e568eca645cab1defa7c4f3566a5193547 | |
parent | 512ccbc01a8f61a524eaaa6762c980499a5a5ed3 (diff) |
Make it possible to jump between files when navigate is active (#684)
* Use distinct navigate label for file and hunk boundaries
Ref #680
* Make it easy to remove hunk label from navigate regex
Thanks @lepotic for the suggestion.
Fixes #680
* Allow regex meta characters to be used in navigate anchors
-rw-r--r-- | src/cli.rs | 4 | ||||
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/features/navigate.rs | 15 | ||||
-rw-r--r-- | src/hunk_header.rs | 6 | ||||
-rw-r--r-- | src/options/set.rs | 1 |
5 files changed, 25 insertions, 5 deletions
@@ -490,6 +490,10 @@ pub struct Opt { /// Text to display in front of a renamed file path. pub file_renamed_label: String, + #[structopt(long = "hunk-label", default_value = "")] + /// Text to display in front of a hunk header. + pub hunk_label: String, + #[structopt(long = "max-line-length", default_value = "512")] /// Truncate lines longer than this. To prevent any truncation, set to zero. Note that /// syntax-highlighting very long lines (e.g. minified .js) will be very slow if they are not diff --git a/src/config.rs b/src/config.rs index 9dfea5d4..1972fa47 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,6 +33,7 @@ pub struct Config { pub file_modified_label: String, pub file_removed_label: String, pub file_renamed_label: String, + pub hunk_label: String, pub file_style: Style, pub git_config_entries: HashMap<String, GitConfigEntry>, pub hunk_header_file_style: Style, @@ -178,6 +179,7 @@ impl From<cli::Opt> for Config { let file_modified_label = opt.file_modified_label; let file_removed_label = opt.file_removed_label; let file_renamed_label = opt.file_renamed_label; + let hunk_label = opt.hunk_label; let navigate_regexp = if opt.navigate || opt.show_themes { Some(navigate::make_navigate_regexp( @@ -186,6 +188,7 @@ impl From<cli::Opt> for Config { &file_added_label, &file_removed_label, &file_renamed_label, + &hunk_label, )) } else { None @@ -208,6 +211,7 @@ impl From<cli::Opt> for Config { file_modified_label, file_removed_label, file_renamed_label, + hunk_label, file_style, git_config_entries: opt.git_config_entries, hunk_header_file_style, diff --git a/src/features/navigate.rs b/src/features/navigate.rs index 4e1e062a..09cfc47e 100644 --- a/src/features/navigate.rs +++ b/src/features/navigate.rs @@ -19,6 +19,12 @@ pub fn make_feature() -> Vec<(String, OptionValueFunction)> { String, None, _opt => "Δ" + ), + ( + "hunk-label", + String, + None, + _opt => "δ" ) ]) } @@ -30,13 +36,18 @@ pub fn make_navigate_regexp( file_added_label: &str, file_removed_label: &str, file_renamed_label: &str, + hunk_label: &str, ) -> String { if show_themes { "^Theme:".to_string() } else { format!( - "^(commit|{}|{}|{}|{})", - file_modified_label, file_added_label, file_removed_label, file_renamed_label, + "^(commit|{}|{}|{}|{}|{})", + regex::escape(file_added_label), + regex::escape(file_removed_label), + regex::escape(file_renamed_label), + regex::escape(file_modified_label), + regex::escape(hunk_label), ) } } diff --git a/src/hunk_header.rs b/src/hunk_header.rs index 0889f41f..3a192526 100644 --- a/src/hunk_header.rs +++ b/src/hunk_header.rs @@ -94,10 +94,10 @@ fn get_painted_file_with_line_number( config: &Config, ) -> String { let mut file_with_line_number = Vec::new(); - let modified_label; + let hunk_label; if config.navigate { - modified_label = format!("{} ", config.file_modified_label); - file_with_line_number.push(config.hunk_header_file_style.paint(&modified_label)); + hunk_label = format!("{} ", config.hunk_label); + file_with_line_number.push(config.hunk_header_file_style.paint(&hunk_label)); } let plus_line_number = line_numbers[line_numbers.len() - 1].0; if config.hunk_header_style_include_file_path { diff --git a/src/options/set.rs b/src/options/set.rs index cf17e2b2..4fc0a1fd 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -132,6 +132,7 @@ pub fn set_options( file_modified_label, file_removed_label, file_renamed_label, + hunk_label, file_style, hunk_header_decoration_style, hunk_header_file_style, |