Skip to content

Commit

Permalink
fix using old preview when deleting and renaming
Browse files Browse the repository at this point in the history
steps to reproduce previous bug:
1. have 2 folders folder1 and folder2
2. delete folder1
3. rename folder2 to folder1
4. expected preview should be folder2's original content
5. actual is folder1's original content
  • Loading branch information
kamiyaa committed Aug 1, 2021
1 parent 97ca1fb commit 45e7a9f
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions src/commands/delete_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ where
}

fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io::Result<()> {
let tab_index = context.tab_context_ref().index;
let paths = match context.tab_context_ref().curr_tab_ref().curr_list_ref() {
Some(s) => s.get_selected_paths(),
None => vec![],
let delete_func = if context.config_ref().use_trash {
trash_files
} else {
remove_files
};

let tab_index = context.tab_context_ref().index;
let paths = context
.tab_context_ref()
.curr_tab_ref()
.curr_list_ref()
.map(|s| s.get_selected_paths())
.unwrap_or(vec![]);
let paths_len = paths.len();
if paths_len == 0 {
return Err(std::io::Error::new(
Expand All @@ -69,46 +77,49 @@ fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io::
));
}

let delete_func = if context.config_ref().use_trash {
trash_files
} else {
remove_files
};

let ch = {
let prompt_str = format!("Delete {} files? (Y/n)", paths_len);
let mut prompt = TuiPrompt::new(&prompt_str);
prompt.get_key(backend, context)
};

if ch == Key::Char('y') || ch == Key::Char('\n') {
if paths_len > 1 {
let ch = {
let prompt_str = "Are you sure? (y/N)";
let mut prompt = TuiPrompt::new(prompt_str);
prompt.get_key(backend, context)
match ch {
Key::Char('y') | Key::Char('\n') => {
let confirm_delete = if paths_len > 1 {
// prompt user again for deleting multiple files
let ch = {
let prompt_str = "Are you sure? (y/N)";
let mut prompt = TuiPrompt::new(prompt_str);
prompt.get_key(backend, context)
};
ch == Key::Char('y')
} else {
true
};
if ch == Key::Char('y') {
if confirm_delete {
delete_func(&paths)?;

// remove directory previews
for tab in context.tab_context_mut().iter_mut() {
for p in &paths {
tab.history_mut().remove(p.as_path());
}
}
reload::reload(context, tab_index)?;
let msg = format!("Deleted {} files", paths_len);
context.push_msg(msg);
}
} else {
delete_func(&paths)?;
reload::reload(context, tab_index)?;
let msg = format!("Deleted {} files", paths_len);
context.push_msg(msg);
Ok(())
}
_ => Ok(()),
}
Ok(())
}

pub fn delete_selected_files(
context: &mut AppContext,
backend: &mut TuiBackend,
) -> std::io::Result<()> {
delete_files(context, backend)?;
let res = delete_files(context, backend)?;

let options = context.config_ref().display_options_ref().clone();
let curr_path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf();
Expand Down

0 comments on commit 45e7a9f

Please sign in to comment.