Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions src/menu/columnar_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,21 @@ impl ColumnarMenu {
.unwrap_or(shortest_base);
let match_len = shortest_base.len();

// Split string so the match text can be styled
let skip_len = suggestion
.value
.chars()
.take_while(|c| is_quote(*c))
.count();
let (match_str, remaining_str) = suggestion
.value
.split_at((match_len + skip_len).min(suggestion.value.len()));
let suggestion_value = &suggestion.value;

// Find match position - look for the base string in the suggestion
// Use rfind to match from the end (for file paths, this will match the filename)
let match_position = suggestion_value.rfind(shortest_base).unwrap_or(0);

// The match is just the part that matches the shortest_base
let match_str = &suggestion_value[match_position
..match_position + match_len.min(suggestion_value.len() - match_position)];

// Prefix is everything before the match
let prefix = &suggestion_value[..match_position];

// Remaining is everything after the match
let remaining_str = &suggestion_value[match_position + match_str.len()..];

let suggestion_style_prefix = suggestion
.style
Expand All @@ -331,14 +337,18 @@ impl ColumnarMenu {
if index == self.index() {
if let Some(description) = &suggestion.description {
format!(
"{}{}{}{}{}{:max_match$}{:max_remaining$}{}{}{}{}{}{}",
"{}{}{}{}{}{}{}{}{}{:max_match$}{:max_remaining$}{}{}{}{}{}{}",
suggestion_style_prefix,
self.settings.color.selected_text_style.prefix(),
prefix,
RESET,
suggestion_style_prefix,
self.settings.color.selected_match_style.prefix(),
match_str,
RESET,
suggestion_style_prefix,
self.settings.color.selected_text_style.prefix(),
&remaining_str,
remaining_str,
RESET,
self.settings.color.description_style.prefix(),
self.settings.color.selected_text_style.prefix(),
Expand All @@ -352,7 +362,11 @@ impl ColumnarMenu {
)
} else {
format!(
"{}{}{}{}{}{}{}{}{:>empty$}{}",
"{}{}{}{}{}{}{}{}{}{}{}{}{:>empty$}{}",
suggestion_style_prefix,
self.settings.color.selected_text_style.prefix(),
prefix,
RESET,
suggestion_style_prefix,
self.settings.color.selected_match_style.prefix(),
match_str,
Expand All @@ -368,7 +382,10 @@ impl ColumnarMenu {
}
} else if let Some(description) = &suggestion.description {
format!(
"{}{}{}{}{:max_match$}{:max_remaining$}{}{}{}{}{}",
"{}{}{}{}{}{}{}{:max_match$}{:max_remaining$}{}{}{}{}{}",
suggestion_style_prefix,
prefix,
RESET,
suggestion_style_prefix,
self.settings.color.match_style.prefix(),
match_str,
Expand All @@ -387,7 +404,10 @@ impl ColumnarMenu {
)
} else {
format!(
"{}{}{}{}{}{}{}{}{:>empty$}{}{}",
"{}{}{}{}{}{}{}{}{}{}{}{:>empty$}{}{}",
suggestion_style_prefix,
prefix,
RESET,
suggestion_style_prefix,
self.settings.color.match_style.prefix(),
match_str,
Expand Down Expand Up @@ -796,6 +816,6 @@ mod tests {

editor.set_buffer("おは".to_string(), UndoBehavior::CreateUndoPoint);
menu.update_values(&mut editor, &mut completer);
assert!(menu.menu_string(2, true).contains("`おは"));
assert!(menu.menu_string(2, true).contains("おは"));
}
}
32 changes: 25 additions & 7 deletions src/menu/ide_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,19 @@ impl IdeMenu {
.unwrap_or(shortest_base);
let match_len = shortest_base.len().min(string.len());

// Split string so the match text can be styled
let skip_len = string.chars().take_while(|c| is_quote(*c)).count();
let (match_str, remaining_str) =
string.split_at((match_len + skip_len).min(string.len()));
// Find match position - look for the base string in the suggestion
// Use rfind to match from the end (for file paths, this will match the filename)
let match_position = string.rfind(shortest_base).unwrap_or(0);

// The match is just the part that matches the shortest_base
let match_str = &string
[match_position..match_position + match_len.min(string.len() - match_position)];

// Prefix is everything before the match
let prefix = &string[..match_position];

// Remaining is everything after the match
let remaining_str = &string[match_position + match_str.len()..];

let suggestion_style_prefix = suggestion
.style
Expand All @@ -532,9 +541,14 @@ impl IdeMenu {

if index == self.index() {
format!(
"{}{}{}{}{}{}{}{}{}{}{}{}",
"{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
vertical_border,
suggestion_style_prefix,
self.settings.color.selected_text_style.prefix(),
prefix,
" ".repeat(padding_right),
RESET,
suggestion_style_prefix,
" ".repeat(padding),
self.settings.color.selected_match_style.prefix(),
match_str,
Expand All @@ -548,9 +562,13 @@ impl IdeMenu {
)
} else {
format!(
"{}{}{}{}{}{}{}{}{}{}{}",
"{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
vertical_border,
suggestion_style_prefix,
prefix,
" ".repeat(padding_right),
RESET,
suggestion_style_prefix,
" ".repeat(padding),
self.settings.color.match_style.prefix(),
match_str,
Expand Down Expand Up @@ -1466,6 +1484,6 @@ mod tests {

editor.set_buffer("おは".to_string(), UndoBehavior::CreateUndoPoint);
menu.update_values(&mut editor, &mut completer);
assert!(menu.menu_string(2, true).contains("`おは"));
assert!(menu.menu_string(2, true).contains("おは"));
}
}