From 5edeea69f943b1a9f7470aabca4fdc7f8631a1df Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 29 Dec 2025 15:57:51 -0700 Subject: [PATCH] Scroll to focused item on tab rescan, fixes #1281 --- src/app.rs | 15 +++++++++++++-- src/tab.rs | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index 7ac0ee2..01ca40a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4153,10 +4153,19 @@ impl Application for App { tab.sort_name = sort.0; tab.sort_direction = sort.1; + let mut tasks = Vec::with_capacity(2); + if let Some(selection_paths) = selection_paths { tab.select_paths(selection_paths); + + // Ensure selected path is scrolled to after redraw + tasks.push(Task::done(cosmic::action::app(Message::TabMessage( + Some(entity), + tab::Message::ScrollToFocused, + )))); } - return clipboard::read_data::().map(|p| { + + tasks.push(clipboard::read_data::().map(|p| { cosmic::action::app(Message::CutPaths(match p { Some(s) => match s.kind { ClipboardKind::Copy => Vec::new(), @@ -4164,7 +4173,9 @@ impl Application for App { }, None => Vec::new(), })) - }); + })); + + return Task::batch(tasks); } } } diff --git a/src/tab.rs b/src/tab.rs index ffde2ac..84dc8b5 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1664,6 +1664,7 @@ pub enum Message { Resize(Rectangle), Scroll(Viewport), ScrollTab(f32), + ScrollToFocused, SearchContext(Location, SearchContextWrapper), SearchReady(bool), SelectAll, @@ -3880,6 +3881,13 @@ impl Tab { .into(), )); } + Message::ScrollToFocused => { + if let Some(offset) = self.select_focus_scroll() { + commands.push(Command::Iced( + scrollable::scroll_to(self.scrollable_id.clone(), offset).into(), + )); + } + } Message::SearchContext(location, context) => { if location == self.location { self.search_context = context.0;