1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 06:12:16 +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)
};
let key_label = if command.keys.is_empty() {
String::new()
} else {
let mut row = vec![
Element::new(&font, ElementContent::Text(icon.to_string()))
.min_width(Some(Dimension::Cells(2.))),
Element::new(&font, ElementContent::Text(label)),
];
if !command.keys.is_empty() {
let (mods, keycode) = &command.keys[0];
let separator = if term_window.config.ui_key_cap_rendering
@ -286,16 +290,9 @@ impl CommandPalette {
}
let keycode =
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(
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)),
row.push(
Element::new(&font, ElementContent::Text(key_label))
.float(Float::Right)
.padding(BoxDimension {
@ -310,8 +307,11 @@ impl CommandPalette {
bg: label_bg.clone(),
text: label_text.clone(),
}),
]),
)
);
}
elements.push(
Element::new(&font, ElementContent::Children(row))
.colors(ElementColors {
border: BorderColor::default(),
bg,