mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00: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
5 changed files with 23 additions and 16 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
cargo publish -p yazi-shared
|
cargo publish -p yazi-shared
|
||||||
cargo publish -p yazi-config
|
cargo publish -p yazi-config
|
||||||
cargo publish -p yazi-proxy
|
cargo publish -p yazi-proxy
|
||||||
|
cargo publish -p yazi-fs
|
||||||
cargo publish -p yazi-adapter
|
cargo publish -p yazi-adapter
|
||||||
cargo publish -p yazi-boot
|
cargo publish -p yazi-boot
|
||||||
cargo publish -p yazi-dds
|
cargo publish -p yazi-dds
|
||||||
|
|
|
||||||
|
|
@ -298,5 +298,5 @@ keymap = [
|
||||||
{ on = "<Down>", run = "arrow 1", desc = "Move cursor down" },
|
{ on = "<Down>", run = "arrow 1", desc = "Move cursor down" },
|
||||||
|
|
||||||
# Filtering
|
# 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 {
|
impl Help {
|
||||||
pub fn escape(&mut self, _: Cmd) {
|
pub fn escape(&mut self, _: Cmd) {
|
||||||
if self.in_filter.is_none() {
|
if self.keyword().is_none() {
|
||||||
return self.toggle(self.layer);
|
return self.toggle(self.layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.keyword = String::new();
|
||||||
self.in_filter = None;
|
self.in_filter = None;
|
||||||
self.filter_apply();
|
self.filter_apply();
|
||||||
render!();
|
render!();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub struct Help {
|
||||||
pub(super) bindings: Vec<&'static Control>,
|
pub(super) bindings: Vec<&'static Control>,
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
keyword: Option<String>,
|
pub(super) keyword: String,
|
||||||
pub(super) in_filter: Option<Input>,
|
pub(super) in_filter: Option<Input>,
|
||||||
|
|
||||||
pub(super) offset: usize,
|
pub(super) offset: usize,
|
||||||
|
|
@ -29,7 +29,7 @@ impl Help {
|
||||||
self.visible = !self.visible;
|
self.visible = !self.visible;
|
||||||
self.layer = layer;
|
self.layer = layer;
|
||||||
|
|
||||||
self.keyword = Some(String::new());
|
self.keyword = String::new();
|
||||||
self.in_filter = None;
|
self.in_filter = None;
|
||||||
self.filter_apply();
|
self.filter_apply();
|
||||||
|
|
||||||
|
|
@ -65,18 +65,16 @@ impl Help {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn filter_apply(&mut self) {
|
pub(super) fn filter_apply(&mut self) {
|
||||||
let kw = self.in_filter.as_ref().map(|i| i.value()).filter(|v| !v.is_empty());
|
let kw = self.in_filter.as_ref().map_or("", |i| i.value());
|
||||||
if self.keyword.as_deref() == kw {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(kw) = kw {
|
if kw.is_empty() {
|
||||||
self.bindings = KEYMAP.get(self.layer).iter().filter(|&c| c.contains(kw)).collect();
|
self.keyword = String::new();
|
||||||
} else {
|
|
||||||
self.bindings = KEYMAP.get(self.layer).iter().collect();
|
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);
|
self.arrow(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -89,8 +87,8 @@ impl Help {
|
||||||
.in_filter
|
.in_filter
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|i| i.value())
|
.map(|i| i.value())
|
||||||
.or(self.keyword.as_deref())
|
.or(Some(self.keyword.as_str()).filter(|&s| !s.is_empty()))
|
||||||
.map(|s| format!("/{}", s))
|
.map(|s| format!("Filter: {}", s))
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Bindings
|
// --- Bindings
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use ratatui::{buffer::Buffer, layout::{self, Constraint, Rect}, text::Line, widgets::Widget};
|
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 super::Bindings;
|
||||||
use crate::Ctx;
|
use crate::Ctx;
|
||||||
|
|
@ -10,6 +10,13 @@ pub(crate) struct Layout<'a> {
|
||||||
|
|
||||||
impl<'a> Layout<'a> {
|
impl<'a> Layout<'a> {
|
||||||
pub fn new(cx: &'a Ctx) -> Self { Self { cx } }
|
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> {
|
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);
|
let chunks = layout::Layout::vertical([Constraint::Fill(1), Constraint::Length(1)]).split(area);
|
||||||
Line::styled(
|
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,
|
THEME.help.footer,
|
||||||
)
|
)
|
||||||
.render(chunks[1], buf);
|
.render(chunks[1], buf);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue