mirror of
https://github.com/sxyazi/yazi.git
synced 2024-11-24 01:48:00 +03:00
feat: add filtering tip in help component (#1361)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
9d1fab84ef
commit
9b7821a161
@ -1,6 +1,7 @@
|
||||
cargo publish -p yazi-shared
|
||||
cargo publish -p yazi-config
|
||||
cargo publish -p yazi-proxy
|
||||
cargo publish -p yazi-fs
|
||||
cargo publish -p yazi-adapter
|
||||
cargo publish -p yazi-boot
|
||||
cargo publish -p yazi-dds
|
||||
|
@ -298,5 +298,5 @@ keymap = [
|
||||
{ on = "<Down>", run = "arrow 1", desc = "Move cursor down" },
|
||||
|
||||
# Filtering
|
||||
{ on = "/", run = "filter", desc = "Apply a filter for the help items" },
|
||||
{ on = "f", run = "filter", desc = "Apply a filter for the help items" },
|
||||
]
|
||||
|
@ -4,10 +4,11 @@ use crate::help::Help;
|
||||
|
||||
impl Help {
|
||||
pub fn escape(&mut self, _: Cmd) {
|
||||
if self.in_filter.is_none() {
|
||||
if self.keyword().is_none() {
|
||||
return self.toggle(self.layer);
|
||||
}
|
||||
|
||||
self.keyword = String::new();
|
||||
self.in_filter = None;
|
||||
self.filter_apply();
|
||||
render!();
|
||||
|
@ -14,7 +14,7 @@ pub struct Help {
|
||||
pub(super) bindings: Vec<&'static Control>,
|
||||
|
||||
// Filter
|
||||
keyword: Option<String>,
|
||||
pub(super) keyword: String,
|
||||
pub(super) in_filter: Option<Input>,
|
||||
|
||||
pub(super) offset: usize,
|
||||
@ -29,7 +29,7 @@ impl Help {
|
||||
self.visible = !self.visible;
|
||||
self.layer = layer;
|
||||
|
||||
self.keyword = Some(String::new());
|
||||
self.keyword = String::new();
|
||||
self.in_filter = None;
|
||||
self.filter_apply();
|
||||
|
||||
@ -65,18 +65,16 @@ impl Help {
|
||||
}
|
||||
|
||||
pub(super) fn filter_apply(&mut self) {
|
||||
let kw = self.in_filter.as_ref().map(|i| i.value()).filter(|v| !v.is_empty());
|
||||
if self.keyword.as_deref() == kw {
|
||||
return;
|
||||
}
|
||||
let kw = self.in_filter.as_ref().map_or("", |i| i.value());
|
||||
|
||||
if let Some(kw) = kw {
|
||||
self.bindings = KEYMAP.get(self.layer).iter().filter(|&c| c.contains(kw)).collect();
|
||||
} else {
|
||||
if kw.is_empty() {
|
||||
self.keyword = String::new();
|
||||
self.bindings = KEYMAP.get(self.layer).iter().collect();
|
||||
} else if self.keyword != kw {
|
||||
self.keyword = kw.to_owned();
|
||||
self.bindings = KEYMAP.get(self.layer).iter().filter(|&c| c.contains(kw)).collect();
|
||||
}
|
||||
|
||||
self.keyword = kw.map(|s| s.to_owned());
|
||||
self.arrow(0);
|
||||
}
|
||||
}
|
||||
@ -89,8 +87,8 @@ impl Help {
|
||||
.in_filter
|
||||
.as_ref()
|
||||
.map(|i| i.value())
|
||||
.or(self.keyword.as_deref())
|
||||
.map(|s| format!("/{}", s))
|
||||
.or(Some(self.keyword.as_str()).filter(|&s| !s.is_empty()))
|
||||
.map(|s| format!("Filter: {}", s))
|
||||
}
|
||||
|
||||
// --- Bindings
|
||||
|
@ -1,5 +1,5 @@
|
||||
use ratatui::{buffer::Buffer, layout::{self, Constraint, Rect}, text::Line, widgets::Widget};
|
||||
use yazi_config::THEME;
|
||||
use yazi_config::{KEYMAP, THEME};
|
||||
|
||||
use super::Bindings;
|
||||
use crate::Ctx;
|
||||
@ -10,6 +10,13 @@ pub(crate) struct Layout<'a> {
|
||||
|
||||
impl<'a> Layout<'a> {
|
||||
pub fn new(cx: &'a Ctx) -> Self { Self { cx } }
|
||||
|
||||
fn tips() -> String {
|
||||
match KEYMAP.help.iter().find(|&c| c.run.iter().any(|c| c.name == "filter")) {
|
||||
Some(c) => format!(" (Press `{}` to filter)", c.on()),
|
||||
None => String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Widget for Layout<'a> {
|
||||
@ -19,7 +26,7 @@ impl<'a> Widget for Layout<'a> {
|
||||
|
||||
let chunks = layout::Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).split(area);
|
||||
Line::styled(
|
||||
help.keyword().unwrap_or_else(|| format!("{}.help", help.layer)),
|
||||
help.keyword().unwrap_or_else(|| format!("{}.help{}", help.layer, Self::tips())),
|
||||
THEME.help.footer,
|
||||
)
|
||||
.render(chunks[1], buf);
|
||||
|
Loading…
Reference in New Issue
Block a user