From d60a1122d46cc67b207456d824b72699b4e1a780 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 24 Jul 2024 10:09:12 +0800 Subject: [PATCH] Scroll to top when list have searched. (#64) --- crates/ui/src/list/list.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index be0fe0de..32d00c91 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -199,10 +199,15 @@ where self._search_task = cx.spawn(|this, mut cx| async move { search.await; + + let _ = this.update(&mut cx, |this, _| { + this.vertical_scroll_handle.scroll_to_item(0); + this.last_query = Some(text); + }); + // Always wait 100ms to avoid flicker Timer::after(Duration::from_millis(100)).await; let _ = this.update(&mut cx, |this, cx| { - this.last_query = Some(text); this.set_loading(false, cx); }); });