feat: add a searchable buffer picker

This commit is contained in:
Valdemar Lorenzen
2026-10-13 13:53:59 +02:00
parent bfdb7c544f
commit f5ba61624f
8 changed files with 239 additions and 62 deletions
+33 -3
View File
@@ -4377,7 +4377,14 @@ fn draw_palette(
} else {
Borders::NONE
})
.title(format!(" Commands · {mode} "));
.title(format!(
" {} · {mode} ",
if palette.buffers {
"Buffers"
} else {
"Commands"
}
));
let content = if bordered { block.inner(panel) } else { panel };
if bordered {
frame.render_widget(block, panel);
@@ -4399,9 +4406,20 @@ fn draw_palette(
);
frame.set_cursor_position((query_area.x + (query_width - offset) as u16, query_area.y));
if palette.entries.is_empty() {
frame.render_widget(Paragraph::new("No matching commands"), results_area);
frame.render_widget(
Paragraph::new(if palette.buffers {
"No matching buffers"
} else {
"No matching commands"
}),
results_area,
);
} else if results_area.height > 0 {
let row_height = usize::from(results_area.height >= 2) + 1;
let row_height = if palette.buffers {
1
} else {
usize::from(results_area.height >= 2) + 1
};
let count = usize::from(results_area.height) / row_height;
let first = palette.selected.saturating_sub(count - 1);
let mut lines = Vec::with_capacity(count * row_height);
@@ -4413,6 +4431,17 @@ fn draw_palette(
if index == palette.selected {
style = style.bg(Color::Blue).add_modifier(Modifier::BOLD);
}
if palette.buffers {
lines.push(
Line::from(format!(
"{} {}",
if index == palette.selected { ">" } else { " " },
entry.label,
))
.style(style),
);
continue;
}
let bindings = if entry.bindings.is_empty() {
"unbound".into()
} else {
@@ -14397,6 +14426,7 @@ end
query: "long\t界e\u{301}z".into(),
entries: vec![],
selected: 0,
buffers: false,
};
for (width, height) in [(12, 6), (8, 2), (1, 1), (1, 2), (8, 1), (12, 6)] {
let area = ratatui::layout::Rect::new(3, 2, width, height);