1
0
mirror of https://github.com/Dummi26/tuifile.git synced 2025-05-29 21:35:44 +02:00

small improvements

This commit is contained in:
Mark 2024-06-12 20:30:39 +02:00
parent a2a6b9575a
commit b7264ddd13
2 changed files with 23 additions and 26 deletions

View File

@ -384,19 +384,20 @@ impl TuiFile {
fn set_current_index_to_visible(&mut self, start: usize, inc: bool) {
let mut i = start;
loop {
if self.dir_content.get(i).is_some_and(|e| e.passes_filter) {
self.set_current_index(i);
if let Some(e) = self.dir_content.get(i) {
if e.passes_filter {
self.set_current_index(i);
return;
}
} else {
return;
}
if inc {
i += 1;
if i >= self.dir_content.len() {
break;
}
} else if i > 0 {
i -= 1;
} else {
break;
return;
}
}
}
@ -407,7 +408,7 @@ impl TuiFile {
self.updates.request_rescan_files();
self.after_rescanning_files.push(Box::new(move |s| {
if let Some(i) = s.dir_content.iter().position(find_by) {
s.set_current_index(i)
s.set_current_index(i);
} else {
s.updates.request_reset_current_index();
}

View File

@ -26,29 +26,25 @@ pub(crate) fn task_copy(
*status.lock().unwrap() = s;
}
let file_from = parent.join(&rel_path);
let file_to = target.join(&rel_path);
let is_dir = file_from.is_dir();
let parent_created = if let Some(parent) = rel_path.parent() {
parent.as_os_str().is_empty() || created.contains(parent)
let file_to = if let Some(parent) = rel_path.parent() {
let mut p = PathBuf::new();
for c in parent.components() {
p.push(c);
if !created.contains(&p) {
p.pop();
break;
}
}
target.join(&p).join(rel_path.file_name().unwrap())
} else {
true
target.join(&rel_path)
};
if parent_created {
if is_dir {
copy_dir(file_from, file_to, copy_recursive);
created.insert(rel_path);
} else {
fs::copy(&file_from, &file_to);
}
if is_dir {
copy_dir(file_from, file_to, copy_recursive);
created.insert(rel_path);
} else {
let rel_path = rel_path.file_name().unwrap();
let file_to = target.join(&rel_path);
if is_dir {
copy_dir(file_from, file_to, copy_recursive);
created.insert(rel_path.into());
} else {
fs::copy(&file_from, &file_to);
}
fs::copy(&file_from, &file_to);
}
}
}