mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: apply logic to check num of selected files
This commit is contained in:
parent
914a296492
commit
59ea72a0da
6 changed files with 15 additions and 11 deletions
|
|
@ -56,7 +56,7 @@ impl Chord {
|
|||
});
|
||||
let whitespace_re = RE.get_or_init(|| Regex::new(r"\s+").unwrap());
|
||||
match result {
|
||||
Cow::Owned(result) => Cow::Owned(whitespace_re.replace_all(&result, "").into_owned()),
|
||||
Cow::Owned(result) => Cow::Owned(whitespace_re.replace_all(&result, " ").into_owned()),
|
||||
Cow::Borrowed(result) => whitespace_re.replace_all(result, " "),
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -16,10 +16,6 @@ impl From<Cmd> for Opt {
|
|||
impl Tab {
|
||||
pub fn copy(&mut self, opt: impl Into<Opt>) {
|
||||
let opt = opt.into() as Opt;
|
||||
if !self.try_escape_visual() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut s = OsString::new();
|
||||
let mut it = self.selected_or_hovered(true).peekable();
|
||||
while let Some(u) = it.next() {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ impl WhichSorter {
|
|||
entities.push(match self.by {
|
||||
SortBy::None => unreachable!(),
|
||||
SortBy::Key => Cow::Owned(ctrl.on()),
|
||||
SortBy::Desc => ctrl.desc_or_run(Plurality::Plural),
|
||||
SortBy::Desc => ctrl.desc_or_run(Plurality::default()),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crossterm::event::KeyCode;
|
||||
use yazi_config::{KEYMAP, keymap::{Chord, Key}};
|
||||
use yazi_shared::{Layer, emit};
|
||||
|
||||
|
|
@ -50,6 +51,13 @@ impl<'a> Router<'a> {
|
|||
}
|
||||
|
||||
if on.len() > 1 {
|
||||
//for `copy` hotkeys starting with 'c', we need to escape visual mode first so that the `Which` UI can check how many files
|
||||
// are selected to decide using plural or singular on command names.
|
||||
if key.code == KeyCode::Char('c') {
|
||||
if !self.app.cx.manager.active_mut().try_escape_visual() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
self.app.cx.which.show_with(key, layer);
|
||||
} else {
|
||||
emit!(Seq(ctrl.to_seq(), layer));
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ use yazi_config::{keymap::{Chord, Plurality}, THEME};
|
|||
pub(super) struct Cand<'a> {
|
||||
cand: &'a Chord,
|
||||
times: usize,
|
||||
selected: usize,
|
||||
}
|
||||
|
||||
impl<'a> Cand<'a> {
|
||||
pub(super) fn new(cand: &'a Chord, times: usize) -> Self { Self { times, cand } }
|
||||
pub(super) fn new(cand: &'a Chord, times: usize, selected: usize) -> Self { Self { times, cand, selected } }
|
||||
|
||||
fn keys(&self) -> Vec<String> {
|
||||
self.cand.on[self.times..].iter().map(ToString::to_string).collect()
|
||||
|
|
@ -32,7 +33,7 @@ impl Widget for Cand<'_> {
|
|||
spans.push(Span::styled(&THEME.which.separator, THEME.which.separator_style));
|
||||
|
||||
// Description
|
||||
spans.push(Span::styled(self.cand.desc_or_run(Plurality::Plural), THEME.which.desc));
|
||||
spans.push(Span::styled(self.cand.desc_or_run(if self.selected > 1 { Plurality::Plural } else { Plurality::Singular }), THEME.which.desc));
|
||||
|
||||
Line::from(spans).render(area, buf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,14 +48,13 @@ impl Widget for Which<'_> {
|
|||
|
||||
yazi_plugin::elements::Clear::default().render(area, buf);
|
||||
Block::new().style(THEME.which.mask).render(area, buf);
|
||||
|
||||
let selected = self.cx.manager.selected_or_hovered(false).count();
|
||||
for y in 0..area.height {
|
||||
for (x, chunk) in chunks.iter().enumerate() {
|
||||
let Some(cand) = which.cands.get(y as usize * cols + x) else {
|
||||
break;
|
||||
};
|
||||
|
||||
Cand::new(cand, which.times).render(Rect { y: chunk.y + y + 1, height: 1, ..*chunk }, buf);
|
||||
Cand::new(cand, which.times, selected).render(Rect { y: chunk.y + y + 1, height: 1, ..*chunk }, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue