mirror of
https://github.com/Dummi26/tuifile.git
synced 2025-05-29 21:35:44 +02:00
small improvements
This commit is contained in:
parent
a2a6b9575a
commit
b7264ddd13
15
src/main.rs
15
src/main.rs
@ -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();
|
||||
}
|
||||
|
34
src/tasks.rs
34
src/tasks.rs
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user