Skip to content

Commit

Permalink
Fix #793 using width() for column menu alignements with special chara…
Browse files Browse the repository at this point in the history
…cters
  • Loading branch information
Jiogo18 committed May 26, 2024
1 parent a580ea5 commit 1ebc1ff
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/menu/columnar_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ 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.width();

// Split string so the match text can be styled
let (match_str, remaining_str) = suggestion.value.split_at(match_len);
Expand Down Expand Up @@ -408,7 +408,7 @@ impl ColumnarMenu {
+ self
.default_details
.col_padding
.saturating_sub(marker.len()),
.saturating_sub(marker.width()),
)
} else {
format!(
Expand All @@ -417,7 +417,7 @@ impl ColumnarMenu {
&suggestion.value,
"",
self.end_of_line(column),
empty = empty_space.saturating_sub(marker.len()),
empty = empty_space.saturating_sub(marker.width()),
)
};

Expand Down Expand Up @@ -500,7 +500,7 @@ impl Menu for ColumnarMenu {
self.working_details.shortest_base_string = base_ranges
.iter()
.map(|range| editor.get_buffer()[range.clone()].to_string())
.min_by_key(|s| s.len())
.min_by_key(|s| s.width())
.unwrap_or_default();

self.reset_position();
Expand Down Expand Up @@ -530,15 +530,15 @@ impl Menu for ColumnarMenu {
self.working_details.col_width = painter.screen_width() as usize;

self.longest_suggestion = self.get_values().iter().fold(0, |prev, suggestion| {
if prev >= suggestion.value.len() {
if prev >= suggestion.value.width() {
prev
} else {
suggestion.value.len()
suggestion.value.width()
}
});
} else {
let max_width = self.get_values().iter().fold(0, |acc, suggestion| {
let str_len = suggestion.value.len() + self.default_details.col_padding;
let str_len = suggestion.value.width() + self.default_details.col_padding;
if str_len > acc {
str_len
} else {
Expand Down Expand Up @@ -654,7 +654,7 @@ impl Menu for ColumnarMenu {
// Correcting the enumerate index based on the number of skipped values
let index = index + skip_values;
let column = index as u16 % self.get_cols();
let empty_space = self.get_width().saturating_sub(suggestion.value.len());
let empty_space = self.get_width().saturating_sub(suggestion.value.width());

self.create_string(suggestion, index, column, empty_space, use_ansi_coloring)
})
Expand Down

0 comments on commit 1ebc1ff

Please sign in to comment.