Handle trim on non-ascii messages

This commit is contained in:
Alvaro Parker 2025-08-17 19:09:16 -04:00
parent 5662056ea3
commit 33fd16c749
No known key found for this signature in database

View file

@ -414,7 +414,6 @@ impl PickerDelegate for StashListDelegate {
Self::format_message(entry_match.entry.index, &entry_match.entry.message);
let mut positions = entry_match.positions.clone();
if stash_message.is_ascii() {
let max_width = self.max_width.to_pixels(window.rem_size());
let normal_em = {
let style = window.text_style();
@ -429,11 +428,14 @@ impl PickerDelegate for StashListDelegate {
let max_chars = ((max_width * 0.8) / normal_em) as usize;
if stash_message.len() > max_chars && max_chars > 3 {
stash_message.truncate(max_chars - 3);
stash_message.push_str("");
positions.retain(|&pos| pos < max_chars - 3);
if stash_message.len() > max_chars && max_chars > 1 {
let mut index = max_chars - 1;
while !stash_message.is_char_boundary(index) && index != 0 {
index -= 1;
}
stash_message.truncate(index);
stash_message.push_str("");
positions.retain(|&pos| pos < index);
}
let stash_name = HighlightedLabel::new(stash_message, positions).into_any_element();