1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 22:33:52 +03:00

palette: refactor slightly

Avoids emitting blank padding for rows that have no key assignments
This commit is contained in:
Wez Furlong 2023-03-25 10:47:50 -07:00
parent c5213b4f85
commit c7e4c7fcd0
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387

View File

@ -262,9 +262,13 @@ impl CommandPalette {
format!("{group}{}. {}", command.brief, command.doc) format!("{group}{}. {}", command.brief, command.doc)
}; };
let key_label = if command.keys.is_empty() { let mut row = vec![
String::new() Element::new(&font, ElementContent::Text(icon.to_string()))
} else { .min_width(Some(Dimension::Cells(2.))),
Element::new(&font, ElementContent::Text(label)),
];
if !command.keys.is_empty() {
let (mods, keycode) = &command.keys[0]; let (mods, keycode) = &command.keys[0];
let separator = if term_window.config.ui_key_cap_rendering let separator = if term_window.config.ui_key_cap_rendering
@ -286,16 +290,9 @@ impl CommandPalette {
} }
let keycode = let keycode =
crate::inputmap::ui_key(keycode, term_window.config.ui_key_cap_rendering); crate::inputmap::ui_key(keycode, term_window.config.ui_key_cap_rendering);
format!("{mod_string}{keycode}") let key_label = format!("{mod_string}{keycode}");
};
elements.push( row.push(
Element::new(
&font,
ElementContent::Children(vec![
Element::new(&font, ElementContent::Text(icon.to_string()))
.min_width(Some(Dimension::Cells(2.))),
Element::new(&font, ElementContent::Text(label)),
Element::new(&font, ElementContent::Text(key_label)) Element::new(&font, ElementContent::Text(key_label))
.float(Float::Right) .float(Float::Right)
.padding(BoxDimension { .padding(BoxDimension {
@ -310,8 +307,11 @@ impl CommandPalette {
bg: label_bg.clone(), bg: label_bg.clone(),
text: label_text.clone(), text: label_text.clone(),
}), }),
]), );
) }
elements.push(
Element::new(&font, ElementContent::Children(row))
.colors(ElementColors { .colors(ElementColors {
border: BorderColor::default(), border: BorderColor::default(),
bg, bg,