From 26634889dc6a5ae3d2720f6511dbfa20eda44a3d Mon Sep 17 00:00:00 2001 From: wowitsjack Date: Sat, 3 Jan 2026 17:10:58 +1000 Subject: [PATCH] scroll to selected item when using type-to-select --- src/app.rs | 6 ++++++ src/dialog.rs | 7 +++++++ src/tab.rs | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 0a80f5a..150627a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3063,6 +3063,12 @@ impl Application for App { if let Some(tab) = self.tab_model.data_mut::(entity) { tab.select_by_prefix(&self.type_select_prefix); + if let Some(offset) = tab.select_focus_scroll() { + return scrollable::scroll_to( + tab.scrollable_id.clone(), + offset, + ); + } } } } diff --git a/src/dialog.rs b/src/dialog.rs index 90b4fd8..aa3a4dc 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -12,6 +12,7 @@ use cosmic::{ futures::{self, SinkExt}, keyboard::{Event as KeyEvent, Key, Modifiers, key::Named}, stream, window, + widget::scrollable, }, iced_core::widget::operation, iced_winit::{self, SurfaceIdWrapper}, @@ -1465,6 +1466,12 @@ impl Application for App { self.type_select_last_key = Some(Instant::now()); self.tab.select_by_prefix(&self.type_select_prefix); + if let Some(offset) = self.tab.select_focus_scroll() { + return scrollable::scroll_to( + self.tab.scrollable_id.clone(), + offset, + ); + } } } } diff --git a/src/tab.rs b/src/tab.rs index 7e21f77..70cbe79 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -2942,7 +2942,7 @@ impl Tab { item.pos_opt.get() } - fn select_focus_scroll(&mut self) -> Option { + pub(crate) fn select_focus_scroll(&mut self) -> Option { let items = self.items_opt.as_ref()?; let item = items.get(self.select_focus?)?; let rect = item.rect_opt.get()?;