Skip to content

Commit

Permalink
fix panic with unicode chars
Browse files Browse the repository at this point in the history
  • Loading branch information
maxomatic458 committed Apr 14, 2024
1 parent b143ae4 commit b2c43d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/menu/columnar_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,21 @@ 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) = if match_len <= suggestion.value.len() {
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::<String>(),
suggestion.value.chars().skip(match_len).collect::<String>(),
)
} else {
("", suggestion.value.as_str())
("".to_string(), suggestion.value.to_string())
};

let suggestion_style_prefix = suggestion
Expand Down
16 changes: 12 additions & 4 deletions src/menu/ide_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,21 @@ 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) = if match_len <= string.len() {
string.split_at(match_len)
let (match_str, remaining_str) = if match_len <= string.chars().count() {
(
string.chars().take(match_len).collect::<String>(),
string.chars().skip(match_len).collect::<String>(),
)
} else {
("", string.as_str())
("".to_string(), string.to_string())
};

let suggestion_style_prefix = suggestion
Expand Down

0 comments on commit b2c43d3

Please sign in to comment.