Skip to content

Commit 4d14e5d

Browse files
authored
menu: Don't apply selected_text style to matched text in suggestions (#994)
1 parent 4cce77d commit 4d14e5d

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/menu/menu_functions.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ pub fn style_suggestion(
444444
let is_match = match_indices.contains(&(i + offset));
445445

446446
if is_match && !prev_matched {
447+
res.push_str(RESET);
448+
res.push_str(&text_style_prefix);
447449
res.push_str(&match_style_prefix);
450+
res.push_str(escape);
448451
} else if !is_match && prev_matched && i != 0 {
449452
res.push_str(RESET);
450453
res.push_str(&text_style_prefix);
@@ -848,12 +851,15 @@ mod tests {
848851
let style2 = Style::new().on(Color::Green);
849852

850853
let expected = format!(
851-
"{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
854+
"{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
852855
text_style.prefix(),
853856
selected_style.prefix(),
854857
style1.prefix(),
855858
"ab",
856-
match_style.paint("汉"),
859+
RESET,
860+
text_style.prefix(),
861+
match_style.prefix(),
862+
style1.paint("汉"),
857863
text_style.prefix(),
858864
selected_style.prefix(),
859865
style1.prefix(),
@@ -866,7 +872,10 @@ mod tests {
866872
text_style.prefix(),
867873
selected_style.prefix(),
868874
style2.prefix(),
869-
match_style.paint("y̆👩🏾"),
875+
RESET,
876+
text_style.prefix(),
877+
match_style.prefix(),
878+
style2.paint("y̆👩🏾"),
870879
text_style.prefix(),
871880
selected_style.prefix(),
872881
style2.prefix(),
@@ -875,7 +884,12 @@ mod tests {
875884
selected_style.prefix(),
876885
RESET,
877886
"b@",
878-
match_style.paint("r"),
887+
RESET,
888+
text_style.prefix(),
889+
match_style.prefix(),
890+
RESET,
891+
"r",
892+
RESET,
879893
);
880894
let match_indices = &[
881895
2, // 汉
@@ -899,7 +913,14 @@ mod tests {
899913
let text_style = Style::new().on(Color::Blue).bold();
900914
let match_style = Style::new().underline();
901915

902-
let expected = format!("{}{}{}", text_style.prefix(), "go", match_style.paint("o"),);
916+
let expected = format!(
917+
"{}{}{}{}{}",
918+
text_style.prefix(),
919+
"go",
920+
RESET,
921+
text_style.prefix(),
922+
match_style.paint("o"),
923+
);
903924
assert_eq!(
904925
expected,
905926
style_suggestion("goo", &[2, 3, 4, 6], &text_style, &match_style, None)

0 commit comments

Comments
 (0)