Skip to content

Commit

Permalink
Merge pull request #199 from deg0nz/fix-fuzzy-select-active-item-colors
Browse files Browse the repository at this point in the history
Fix: [Fuzzy-Select] Apply active style to active item
  • Loading branch information
pksunkara committed May 29, 2022
2 parents 3f16bde + 5a7c2b0 commit fa4c119
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/theme.rs
Expand Up @@ -340,7 +340,7 @@ impl Default for ColorfulTheme {
#[cfg(feature = "fuzzy-select")]
fuzzy_cursor_style: Style::new().for_stderr().black().on_white(),
#[cfg(feature = "fuzzy-select")]
fuzzy_match_highlight_style: Style::new().for_stderr().bold().yellow(),
fuzzy_match_highlight_style: Style::new().for_stderr().bold(),
inline_selections: true,
}
}
Expand Down Expand Up @@ -625,15 +625,36 @@ impl Theme for ColorfulTheme {
matcher: &SkimMatcherV2,
search_term: &str,
) -> fmt::Result {
write!(f, "{} ", if active { ">" } else { " " })?;
write!(
f,
"{} ",
if active {
&self.active_item_prefix
} else {
&self.inactive_item_prefix
}
)?;

if highlight_matches {
if let Some((_score, indices)) = matcher.fuzzy_indices(text, &search_term) {
for (idx, c) in text.chars().into_iter().enumerate() {
if indices.contains(&idx) {
write!(f, "{}", self.fuzzy_match_highlight_style.apply_to(c))?;
if active {
write!(
f,
"{}",
self.active_item_style
.apply_to(self.fuzzy_match_highlight_style.apply_to(c))
)?;
} else {
write!(f, "{}", self.fuzzy_match_highlight_style.apply_to(c))?;
}
} else {
write!(f, "{}", c)?;
if active {
write!(f, "{}", self.active_item_style.apply_to(c))?;
} else {
write!(f, "{}", c)?;
}
}
}

Expand Down

0 comments on commit fa4c119

Please sign in to comment.