mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
1a5a84e3b1
commit
ee9faac87c
5 changed files with 22 additions and 17 deletions
|
|
@ -16,13 +16,15 @@ impl From<Cmd> for Opt {
|
|||
impl Manager {
|
||||
pub fn paste(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
|
||||
let opt = opt.into() as Opt;
|
||||
let (src, dest) = (self.yanked.iter().collect::<Vec<_>>(), self.cwd());
|
||||
|
||||
let dest = self.cwd();
|
||||
if self.yanked.cut {
|
||||
tasks.file_cut(&self.yanked, dest, opt.force);
|
||||
tasks.file_cut(&src, dest, opt.force);
|
||||
|
||||
self.tabs.iter_mut().for_each(|t| _ = t.selected.remove_many(&src, false));
|
||||
self.unyank(());
|
||||
} else {
|
||||
tasks.file_copy(&self.yanked, dest, opt.force, opt.follow);
|
||||
tasks.file_copy(&src, dest, opt.force, opt.follow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,9 +52,13 @@ impl Manager {
|
|||
|
||||
pub fn remove_do(&mut self, opt: impl Into<Opt>, tasks: &Tasks) {
|
||||
let opt = opt.into() as Opt;
|
||||
|
||||
self.tabs.iter_mut().for_each(|t| {
|
||||
t.selected.remove_many(&opt.targets, false);
|
||||
});
|
||||
|
||||
for u in &opt.targets {
|
||||
self.yanked.remove(u);
|
||||
self.tabs.iter_mut().for_each(|t| _ = t.selected.remove(u));
|
||||
}
|
||||
|
||||
tasks.file_remove(opt.targets, opt.permanently);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ impl Manager {
|
|||
for (_, tab) in self.tabs.iter_mut().enumerate().filter(|(i, _)| *i != idx) {
|
||||
Self::update_tab(tab, Cow::Borrowed(&op), tasks);
|
||||
}
|
||||
|
||||
Self::update_tab(self.active_mut(), Cow::Owned(op), tasks);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,27 +63,27 @@ impl Selected {
|
|||
#[inline]
|
||||
pub fn remove(&mut self, url: &Url) -> bool { self.remove_same(&[url]) == 1 }
|
||||
|
||||
pub fn remove_many(&mut self, urls: &[&Url], same: bool) -> usize {
|
||||
pub fn remove_many(&mut self, urls: &[impl AsRef<Url>], same: bool) -> usize {
|
||||
if same {
|
||||
return self.remove_same(urls);
|
||||
}
|
||||
|
||||
let mut grouped: HashMap<_, Vec<_>> = Default::default();
|
||||
for &u in urls {
|
||||
if let Some(p) = u.parent_url() {
|
||||
for u in urls {
|
||||
if let Some(p) = u.as_ref().parent_url() {
|
||||
grouped.entry(p).or_default().push(u);
|
||||
}
|
||||
}
|
||||
grouped.into_values().map(|v| self.remove_same(&v)).sum()
|
||||
}
|
||||
|
||||
fn remove_same(&mut self, urls: &[&Url]) -> usize {
|
||||
let count = urls.iter().map(|&u| self.inner.remove(u)).filter(|&b| b).count();
|
||||
fn remove_same(&mut self, urls: &[impl AsRef<Url>]) -> usize {
|
||||
let count = urls.iter().map(|u| self.inner.remove(u.as_ref())).filter(|&b| b).count();
|
||||
if count == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let mut parent = urls[0].parent_url();
|
||||
let mut parent = urls[0].as_ref().parent_url();
|
||||
while let Some(u) = parent {
|
||||
let n = self.parents.get_mut(&u).unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -78,10 +78,10 @@ impl Tasks {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn file_cut(&self, src: &HashSet<Url>, dest: &Url, force: bool) {
|
||||
for u in src {
|
||||
pub fn file_cut(&self, src: &[&Url], dest: &Url, force: bool) {
|
||||
for &u in src {
|
||||
let to = dest.join(u.file_name().unwrap());
|
||||
if force && u == &to {
|
||||
if force && *u == to {
|
||||
debug!("file_cut: same file, skipping {:?}", to);
|
||||
} else {
|
||||
self.scheduler.file_cut(u.clone(), to, force);
|
||||
|
|
@ -89,10 +89,10 @@ impl Tasks {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn file_copy(&self, src: &HashSet<Url>, dest: &Url, force: bool, follow: bool) {
|
||||
for u in src {
|
||||
pub fn file_copy(&self, src: &[&Url], dest: &Url, force: bool, follow: bool) {
|
||||
for &u in src {
|
||||
let to = dest.join(u.file_name().unwrap());
|
||||
if force && u == &to {
|
||||
if force && *u == to {
|
||||
debug!("file_copy: same file, skipping {:?}", to);
|
||||
} else {
|
||||
self.scheduler.file_copy(u.clone(), to, force, follow);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue