fix: file list expansion arguments ($@, $*) of shell command under opener rules are out of order (#890)

This commit is contained in:
三咲雅 · Misaki Masa 2024-04-10 08:31:03 +08:00 committed by GitHub
parent 884de41b66
commit e7dc971416
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 28 additions and 24 deletions

View File

@ -15,7 +15,7 @@ impl Manager {
};
let cwd = self.cwd().clone();
let old: Vec<_> = self.selected_or_hovered(true);
let old: Vec<_> = self.selected_or_hovered(true).collect();
let root = max_common_root(&old);
let old: Vec<_> = old.into_iter().map(|p| p.strip_prefix(&root).unwrap().to_owned()).collect();

View File

@ -33,7 +33,9 @@ impl Manager {
};
let opt = opt.into() as Opt;
let selected = if opt.hovered { vec![&hovered] } else { self.selected_or_hovered(false) };
let selected =
if opt.hovered { vec![&hovered] } else { self.selected_or_hovered(true).collect() };
if Self::quit_with_selected(&selected) {
return;
}

View File

@ -27,7 +27,7 @@ impl Manager {
}
let mut opt = opt.into() as Opt;
opt.targets = self.selected_or_hovered(false).into_iter().cloned().collect();
opt.targets = self.selected_or_hovered(false).cloned().collect();
if opt.force {
return self.remove_do(opt, tasks);

View File

@ -17,10 +17,8 @@ impl Manager {
return;
}
self.yanked = Yanked {
cut: opt.into().cut,
urls: self.selected_or_hovered(false).into_iter().cloned().collect(),
};
self.yanked =
Yanked { cut: opt.into().cut, urls: self.selected_or_hovered(false).cloned().collect() };
self.active_mut().escape_select();
Pubsub::pub_from_yank(self.yanked.cut, &self.yanked.urls);

View File

@ -53,10 +53,12 @@ impl Manager {
pub fn hovered_folder(&self) -> Option<&Folder> { self.tabs.active().hovered_folder() }
#[inline]
pub fn selected_or_hovered(&self, sorted: bool) -> Vec<&Url> {
self.tabs.active().selected_or_hovered(sorted)
pub fn selected_or_hovered(&self, reorder: bool) -> Box<dyn Iterator<Item = &Url> + '_> {
self.tabs.active().selected_or_hovered(reorder)
}
#[inline]
pub fn hovered_and_selected(&self) -> Vec<&Url> { self.tabs.active().hovered_and_selected() }
pub fn hovered_and_selected(&self, reorder: bool) -> Box<dyn Iterator<Item = &Url> + '_> {
self.tabs.active().hovered_and_selected(reorder)
}
}

View File

@ -20,7 +20,7 @@ impl Tab {
}
let mut s = OsString::new();
let mut it = self.selected_or_hovered(true).into_iter().peekable();
let mut it = self.selected_or_hovered(true).peekable();
while let Some(u) = it.next() {
s.push(match opt.type_.as_str() {
"path" => u.as_os_str(),

View File

@ -31,7 +31,7 @@ impl Tab {
}
let mut opt = opt.into() as Opt;
let selected = self.hovered_and_selected().into_iter().cloned().collect();
let selected = self.hovered_and_selected(true).cloned().collect();
tokio::spawn(async move {
if !opt.confirm || opt.run.is_empty() {

View File

@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, iter};
use anyhow::Result;
use tokio::task::JoinHandle;
@ -34,27 +34,29 @@ impl Tab {
impl Tab {
// --- Current
pub fn selected_or_hovered(&self, sorted: bool) -> Vec<&Url> {
pub fn selected_or_hovered(&self, reorder: bool) -> Box<dyn Iterator<Item = &Url> + '_> {
if self.selected.is_empty() {
self.current.hovered().map(|h| vec![&h.url]).unwrap_or_default()
} else if !sorted {
self.selected.keys().collect()
Box::new(self.current.hovered().map(|h| vec![&h.url]).unwrap_or_default().into_iter())
} else if !reorder {
Box::new(self.selected.keys())
} else {
let mut vec: Vec<_> = self.selected.iter().collect();
vec.sort_unstable_by(|a, b| a.1.cmp(b.1));
vec.into_iter().map(|(k, _)| k).collect()
Box::new(vec.into_iter().map(|(k, _)| k))
}
}
pub fn hovered_and_selected(&self) -> Vec<&Url> {
let Some(h) = self.current.hovered() else {
return vec![];
};
pub fn hovered_and_selected(&self, reorder: bool) -> Box<dyn Iterator<Item = &Url> + '_> {
let Some(h) = self.current.hovered() else { return Box::new(iter::empty()) };
if self.selected.is_empty() {
vec![&h.url, &h.url]
Box::new([&h.url, &h.url].into_iter())
} else if !reorder {
Box::new([&h.url].into_iter().chain(self.selected.keys()))
} else {
[&h.url].into_iter().chain(self.selected.keys()).collect()
let mut vec: Vec<_> = self.selected.iter().collect();
vec.sort_unstable_by(|a, b| a.1.cmp(b.1));
Box::new([&h.url].into_iter().chain(vec.into_iter().map(|(k, _)| k)))
}
}