From e947bee8330d97e3442f5d1f14172a6a508a1ee0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 28 May 2024 09:28:46 -0600 Subject: [PATCH] Update tab location when drag and dropping, fixes #178 --- src/app.rs | 22 +++++++++++++++------- src/tab.rs | 34 +++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/app.rs b/src/app.rs index 0f70b15..a474d35 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1630,13 +1630,21 @@ impl Application for App { { self.nav_dnd_hover = None; let entity = self.tab_model.active(); - let title = location.to_string(); - self.tab_model.text_set(entity, title); - return Command::batch([ - self.update_title(), - self.update_watcher(), - self.rescan_tab(entity, location), - ]); + let title_opt = match self.tab_model.data_mut::(entity) { + Some(tab) => { + tab.change_location(&location, None); + Some(tab.title()) + } + None => None, + }; + if let Some(title) = title_opt { + self.tab_model.text_set(entity, title); + return Command::batch([ + self.update_title(), + self.update_watcher(), + self.rescan_tab(entity, location), + ]); + } } } Message::DndEnterTab(entity) => { diff --git a/src/tab.rs b/src/tab.rs index 310b80f..33e2134 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -988,6 +988,24 @@ impl Tab { last } + pub fn change_location(&mut self, location: &Location, history_i_opt: Option) { + self.location = location.clone(); + self.items_opt = None; + self.select_focus = None; + self.edit_location = None; + if let Some(history_i) = history_i_opt { + // Navigating in history + self.history_i = history_i; + } else { + // Truncate history to remove next entries + self.history.truncate(self.history_i + 1); + + // Push to the front of history + self.history_i = self.history.len(); + self.history.push(location.clone()); + } + } + pub fn update(&mut self, message: Message, modifiers: Modifiers) -> Vec { let mut commands = Vec::new(); let mut cd = None; @@ -1442,21 +1460,7 @@ impl Tab { Location::Path(path) => path.is_dir(), Location::Trash => true, } { - self.location = location.clone(); - self.items_opt = None; - self.select_focus = None; - self.edit_location = None; - if let Some(history_i) = history_i_opt { - // Navigating in history - self.history_i = history_i; - } else { - // Truncate history to remove next entries - self.history.truncate(self.history_i + 1); - - // Push to the front of history - self.history_i = self.history.len(); - self.history.push(location.clone()); - } + self.change_location(&location, history_i_opt); commands.push(Command::ChangeLocation(self.title(), location)); } else { log::warn!("tried to cd to {:?} which is not a directory", location);