tweak the find hit highlighting (#5981)

This commit is contained in:
Darren Schroeder 2022-07-07 11:32:58 -05:00 committed by GitHub
parent b19cc799aa
commit eac5f62959
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -85,6 +85,7 @@ fn help(
if let Some(f) = find { if let Some(f) = find {
let replace_string = White.on(Red).paint(f.item.clone()).to_string(); let replace_string = White.on(Red).paint(f.item.clone()).to_string();
let org_search_string = f.item.clone();
let search_string = f.item.to_lowercase(); let search_string = f.item.to_lowercase();
let mut found_cmds_vec = Vec::new(); let mut found_cmds_vec = Vec::new();
@ -112,7 +113,7 @@ fn help(
cols.push("name".into()); cols.push("name".into());
vals.push(Value::String { vals.push(Value::String {
val: if key_match { val: if key_match {
key.as_str().replace(&key, &replace_string) key.as_str().replace(&org_search_string, &replace_string)
} else { } else {
key key
}, },
@ -146,7 +147,7 @@ fn help(
cols.push("usage".into()); cols.push("usage".into());
vals.push(Value::String { vals.push(Value::String {
val: if use_match { val: if use_match {
usage.as_str().replace(&usage, &replace_string) usage.as_str().replace(&org_search_string, &replace_string)
} else { } else {
usage usage
}, },
@ -163,7 +164,7 @@ fn help(
.iter() .iter()
.map(|term| { .map(|term| {
if term.to_lowercase().contains(&search_string) { if term.to_lowercase().contains(&search_string) {
term.replace(term, &replace_string.clone()) term.replace(&org_search_string, &replace_string.clone())
} else { } else {
term.clone() term.clone()
} }