diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs index 6e54c247..dc669b5b 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -121,19 +121,19 @@ impl ConfirmCfg { pub fn trash(urls: &[yazi_shared::fs::Url]) -> Self { Self::new( - Self::replace_number(&CONFIRM.trash_title, urls.len(), usize::MAX), + Self::replace_number(&CONFIRM.trash_title, urls.len()), (CONFIRM.trash_origin, CONFIRM.trash_offset), None, - Some(urls.iter().map(ToString::to_string).collect()), + Self::truncate_list(urls.iter(), urls.len(), 100), ) } pub fn delete(urls: &[yazi_shared::fs::Url]) -> Self { Self::new( - Self::replace_number(&CONFIRM.delete_title, urls.len(), usize::MAX), + Self::replace_number(&CONFIRM.delete_title, urls.len()), (CONFIRM.delete_origin, CONFIRM.delete_offset), None, - Some(urls.iter().map(ToString::to_string).collect()), + Self::truncate_list(urls.iter(), urls.len(), 100), ) } @@ -146,18 +146,33 @@ impl ConfirmCfg { ) } - pub fn quit(left: Vec) -> Self { + pub fn quit(len: usize, names: Vec) -> Self { Self::new( - Self::replace_number(&CONFIRM.quit_title, left.len(), 10), + Self::replace_number(&CONFIRM.quit_title, len), (CONFIRM.quit_origin, CONFIRM.quit_offset), Some(Text::raw(&CONFIRM.quit_content)), - Some(left.into_iter().collect()), + Self::truncate_list(names.into_iter(), len, 10), ) } - fn replace_number(tpl: &str, n: usize, max: usize) -> String { - let s = tpl.replace("{s}", if n > 1 { "s" } else { "" }); - s.replace("{n}", &if n > max { format!("{max}+") } else { n.to_string() }) + fn replace_number(tpl: &str, n: usize) -> String { + tpl.replace("{n}", &n.to_string()).replace("{s}", if n > 1 { "s" } else { "" }) + } + + fn truncate_list( + it: impl Iterator>, + len: usize, + max: usize, + ) -> Option> { + let mut lines = Vec::with_capacity(len.min(max + 1)); + for (i, s) in it.enumerate() { + if i >= max { + lines.push(format!("... and {} more", len - max)); + break; + } + lines.push(s.into()); + } + Some(Text::from_iter(lines)) } } diff --git a/yazi-core/src/manager/commands/quit.rs b/yazi-core/src/manager/commands/quit.rs index fbbdb929..0442ffbd 100644 --- a/yazi-core/src/manager/commands/quit.rs +++ b/yazi-core/src/manager/commands/quit.rs @@ -23,16 +23,19 @@ impl Manager { let opt = EventQuit { no_cwd_file: opt.into().no_cwd_file, ..Default::default() }; let ongoing = tasks.ongoing().clone(); - let left: Vec = ongoing.lock().values().take(11).map(|t| t.name.clone()).collect(); + let (left, left_names) = { + let ongoing = ongoing.lock(); + (ongoing.len(), ongoing.values().take(11).map(|t| t.name.clone()).collect()) + }; - if left.is_empty() { + if left == 0 { emit!(Quit(opt)); return; } tokio::spawn(async move { let mut i = 0; - let mut rx = ConfirmProxy::show_rx(ConfirmCfg::quit(left)); + let mut rx = ConfirmProxy::show_rx(ConfirmCfg::quit(left, left_names)); loop { select! { _ = time::sleep(Duration::from_millis(100)) => { diff --git a/yazi-core/src/manager/commands/tab_create.rs b/yazi-core/src/manager/commands/tab_create.rs index d3216b1c..72d77c71 100644 --- a/yazi-core/src/manager/commands/tab_create.rs +++ b/yazi-core/src/manager/commands/tab_create.rs @@ -35,7 +35,7 @@ impl Tabs { } let opt = opt.into() as Opt; - let mut tab = Tab::default(); + let mut tab = Tab { idx: self.cursor + 1, ..Default::default() }; if !opt.current { tab.cd(opt.url); diff --git a/yazi-core/src/tab/tab.rs b/yazi-core/src/tab/tab.rs index 0df8a13a..32dad746 100644 --- a/yazi-core/src/tab/tab.rs +++ b/yazi-core/src/tab/tab.rs @@ -23,9 +23,9 @@ pub struct Tab { pub history: HashMap, pub selected: Selected, - pub preview: Preview, - pub finder: Option, - pub(super) search: Option>>, + pub preview: Preview, + pub finder: Option, + pub search: Option>>, } impl Tab { diff --git a/yazi-shared/src/fs/url.rs b/yazi-shared/src/fs/url.rs index 68aaebd2..274931f2 100644 --- a/yazi-shared/src/fs/url.rs +++ b/yazi-shared/src/fs/url.rs @@ -118,6 +118,10 @@ impl Display for Url { } } +impl From<&Url> for String { + fn from(url: &Url) -> Self { url.to_string() } +} + impl Url { #[inline] pub fn join(&self, path: impl AsRef) -> Self {