From 567c617b28c2e0f3ba0468e770eac72391a22bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Fri, 8 Sep 2023 06:47:51 +0800 Subject: [PATCH] fix: `show_hidden` not properly applied to hovered folder (#124) --- core/src/manager/manager.rs | 9 ++++++--- core/src/manager/tab.rs | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/core/src/manager/manager.rs b/core/src/manager/manager.rs index a7761e68..7159a3ff 100644 --- a/core/src/manager/manager.rs +++ b/core/src/manager/manager.rs @@ -30,7 +30,7 @@ impl Manager { pub fn refresh(&mut self) { env::set_current_dir(self.cwd()).ok(); - self.active_mut().apply_show_hidden(); + self.active_mut().apply_show_hidden(false); if let Some(f) = self.parent() { self.watcher.trigger_dirs(&[self.cwd(), &f.cwd]); @@ -342,10 +342,13 @@ impl Manager { self.current_mut().update(op) } else if matches!(self.parent(), Some(p) if p.cwd == url) { self.active_mut().parent.as_mut().unwrap().update(op) + } else if matches!(self.hovered(), Some(h) if h.url() == &url) { + self.active_mut().history.entry(url.clone()).or_insert_with(|| Folder::from(&url)); + self.active_mut().apply_show_hidden(true); + self.active_mut().history.get_mut(&url).unwrap().update(op) } else { self.active_mut().history.entry(url.clone()).or_insert_with(|| Folder::from(&url)).update(op); - - matches!(self.hovered(), Some(h) if h.url() == &url) + false }; b |= self.active_mut().parent.as_mut().map_or(false, |p| p.hover(&cwd)); diff --git a/core/src/manager/tab.rs b/core/src/manager/tab.rs index 9bb6a96d..162f0101 100644 --- a/core/src/manager/tab.rs +++ b/core/src/manager/tab.rs @@ -422,28 +422,29 @@ impl Tab { } self.show_hidden = state; - self.apply_show_hidden(); + self.apply_show_hidden(false); true } - pub fn apply_show_hidden(&mut self) -> bool { + pub fn apply_show_hidden(&mut self, only_hovered: bool) -> bool { let state = self.show_hidden; - - let mut applied = false; - applied |= self.current.files.set_show_hidden(state); - - if let Some(parent) = self.parent.as_mut() { - applied |= parent.files.set_show_hidden(state); - } - - applied |= match self.current.hovered { + let mut b = match self.current.hovered { Some(ref h) if h.is_dir() => { self.history.get_mut(h.url()).map(|f| f.files.set_show_hidden(state)) == Some(true) } _ => false, }; + if only_hovered { + return b; + } + + b |= self.current.files.set_show_hidden(state); + if let Some(parent) = self.parent.as_mut() { + b |= parent.files.set_show_hidden(state); + } + self.current.hover_repos(); - applied + b } }