From 5a3c63df1727c37a8cba9d7c57b4df31c1f80392 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 25 Sep 2024 15:32:54 -0600 Subject: [PATCH] Scroll to the top after changing location, fixes #448 --- src/tab.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tab.rs b/src/tab.rs index e1c088a..8a2c220 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1704,10 +1704,12 @@ impl Tab { 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.context_menu = None; self.edit_location = None; + self.items_opt = None; + //TODO: remember scroll by location? + self.scroll_opt = None; + self.select_focus = None; if let Some(history_i) = history_i_opt { // Navigating in history self.history_i = history_i; @@ -2493,6 +2495,16 @@ impl Tab { } } + // Scroll to top if needed + if self.scroll_opt.is_none() { + let offset = AbsoluteOffset { x: 0.0, y: 0.0 }; + self.scroll_opt = Some(offset); + commands.push(Command::Iced(scrollable::scroll_to( + self.scrollable_id.clone(), + offset, + ))); + } + // Change directory if requested if let Some(location) = cd { if matches!(self.mode, Mode::Desktop) { @@ -4009,7 +4021,7 @@ impl Tab { //TODO: configurable thumbnail size? let thumbnail_size = (ICON_SIZE_GRID * ICON_SCALE_MAX) as u32; let thumbnail = ItemThumbnail::new(&path, mime, thumbnail_size); - log::info!("thumbnailed {:?} in {:?}", path, start.elapsed()); + log::debug!("thumbnailed {:?} in {:?}", path, start.elapsed()); (path, thumbnail) }) .await