This commit is contained in:
sxyazi 2024-08-02 15:17:57 +08:00
parent 86d16a032a
commit a05cdd9f9b
No known key found for this signature in database
5 changed files with 22 additions and 28 deletions

View file

@ -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

View file

@ -30,18 +30,6 @@ impl Keymap {
Layer::Which => unreachable!(),
}
}
pub fn get_shortcut_for_command(&self, cmd_name: &str, layer: Layer) -> Option<String> {
let control = self
.get(layer)
.iter()
.find(|&c| c.run.iter().any(|cmd| cmd.name.eq(cmd_name)));
match control {
Some(c) => Some(c.on()),
None => None
}
}
}
impl FromStr for Keymap {

View file

@ -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!();

View file

@ -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

View file

@ -1,6 +1,6 @@
use ratatui::{buffer::Buffer, layout::{self, Constraint, Rect}, text::Line, widgets::Widget};
use yazi_config::{KEYMAP, THEME};
use yazi_shared::Layer;
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> {
@ -18,9 +25,8 @@ impl<'a> Widget for Layout<'a> {
yazi_plugin::elements::Clear::default().render(area, buf);
let chunks = layout::Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).split(area);
let filter_key = KEYMAP.get_shortcut_for_command("filter", Layer::Help).unwrap_or_else(|| "[undefined]".into());
Line::styled(
help.keyword().unwrap_or_else(|| format!("{}.help (press {} to filter)", help.layer, filter_key)),
help.keyword().unwrap_or_else(|| format!("{}.help{}", help.layer, Self::tips())),
THEME.help.footer,
)
.render(chunks[1], buf);