diff --git a/src/menu/columnar_menu.rs b/src/menu/columnar_menu.rs index 6eac27ab..8efa34a4 100644 --- a/src/menu/columnar_menu.rs +++ b/src/menu/columnar_menu.rs @@ -299,10 +299,22 @@ impl ColumnarMenu { use_ansi_coloring: bool, ) -> String { if use_ansi_coloring { - let match_len = self.working_details.shortest_base_string.len(); + let match_len = self + .working_details + .shortest_base_string + .trim_end() + .chars() + .count(); // Split string so the match text can be styled - let (match_str, remaining_str) = suggestion.value.split_at(match_len); + let (match_str, remaining_str) = if match_len <= suggestion.value.chars().count() { + ( + suggestion.value.chars().take(match_len).collect::(), + suggestion.value.chars().skip(match_len).collect::(), + ) + } else { + ("".to_string(), suggestion.value.to_string()) + }; let suggestion_style_prefix = suggestion .style diff --git a/src/menu/ide_menu.rs b/src/menu/ide_menu.rs index 2ce711f6..da761a61 100644 --- a/src/menu/ide_menu.rs +++ b/src/menu/ide_menu.rs @@ -512,10 +512,22 @@ impl IdeMenu { }; if use_ansi_coloring { - let match_len = self.working_details.shortest_base_string.len(); + let match_len = self + .working_details + .shortest_base_string + .trim_end() + .chars() + .count(); // Split string so the match text can be styled - let (match_str, remaining_str) = string.split_at(match_len); + let (match_str, remaining_str) = if match_len <= string.chars().count() { + ( + string.chars().take(match_len).collect::(), + string.chars().skip(match_len).collect::(), + ) + } else { + ("".to_string(), string.to_string()) + }; let suggestion_style_prefix = suggestion .style