Update tab location when drag and dropping, fixes #178

This commit is contained in:
Jeremy Soller 2024-05-28 09:28:46 -06:00
parent e3f0f5b776
commit e947bee833
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
2 changed files with 34 additions and 22 deletions

View file

@ -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::<Tab>(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) => {

View file

@ -988,6 +988,24 @@ impl Tab {
last
}
pub fn change_location(&mut self, location: &Location, history_i_opt: Option<usize>) {
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<Command> {
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);