diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-11-07 21:55:23 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-11-07 21:55:23 +0100 |
commit | fa0f1190f65391b4c03f2907c14e4efa33b293d2 (patch) | |
tree | 41bd4c8f673fec8814da1b0a907c27a09ef555fc | |
parent | ed9c1484827f15c55a6a2baf70d9af5c05129928 (diff) |
tree users refactor
-rw-r--r-- | src/status.rs | 19 | ||||
-rw-r--r-- | src/tab.rs | 12 |
2 files changed, 13 insertions, 18 deletions
diff --git a/src/status.rs b/src/status.rs index e5d9183..59988df 100644 --- a/src/status.rs +++ b/src/status.rs @@ -405,20 +405,11 @@ impl Status { pub fn cut_or_copy_flagged_files(&mut self, cut_or_copy: CopyMove) -> Result<()> { let sources = self.flagged.content.clone(); - let dest = match self.selected_non_mut().previous_mode { - Mode::Tree => self - .selected_non_mut() - .tree - .directory_of_selected() - .context("no parent")? - .display() - .to_string(), - _ => self - .selected_non_mut() - .path_content_str() - .context("cut or copy: unreadable path")? - .to_owned(), - }; + let dest = self + .selected_non_mut() + .directory_of_selected_previous_mode()? + .display() + .to_string(); copy_move(cut_or_copy, sources, &dest, Arc::clone(&self.term))?; self.clear_flags_and_reset_view() @@ -146,7 +146,11 @@ impl Tab { self.input.reset(); self.preview = Preview::empty(); self.completion.reset(); - self.tree = Tree::default(); + if matches!(self.mode, Mode::Tree) { + self.tree = Tree::default() + } else { + self.make_tree(None)?; + }; Ok(()) } @@ -387,11 +391,11 @@ impl Tab { } /// Returns the current path. - /// In tree mode : + /// If previous mode was tree mode : /// if the selected node is a directory, that's it. /// else, it is the parent of the selected node. /// In other modes, it's the current path of pathcontent. - pub fn directory_of_selected_previous_mode(&mut self) -> Result<&path::Path> { + pub fn directory_of_selected_previous_mode(&self) -> Result<&path::Path> { match self.previous_mode { Mode::Tree => return self.tree.directory_of_selected().context("no parent"), _ => Ok(&self.path_content.path), @@ -409,7 +413,7 @@ impl Tab { } } - /// Optional Fileinfo of the selected element. + /// Fileinfo of the selected element. pub fn selected(&self) -> Result<FileInfo> { match self.mode { Mode::Tree => { |