From a48232cefd43a1f99af00c79a549a263ffd9c154 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 3 Oct 2025 16:11:27 +0800 Subject: [PATCH] input: Clean to reset selection and scroll offset. (#1326) - Focus back to input when click `clean` button. --- crates/ui/src/input/state.rs | 2 ++ crates/ui/src/input/text_input.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/crates/ui/src/input/state.rs b/crates/ui/src/input/state.rs index 34a3b863..1750046f 100644 --- a/crates/ui/src/input/state.rs +++ b/crates/ui/src/input/state.rs @@ -1512,6 +1512,8 @@ impl InputState { pub(super) fn clean(&mut self, window: &mut Window, cx: &mut Context) { self.replace_text("", window, cx); + self.selected_range = (0..0).into(); + self.scroll_to(0, cx); } pub(super) fn escape(&mut self, action: &Escape, window: &mut Window, cx: &mut Context) { diff --git a/crates/ui/src/input/text_input.rs b/crates/ui/src/input/text_input.rs index 49af7792..2c07d0d1 100644 --- a/crates/ui/src/input/text_input.rs +++ b/crates/ui/src/input/text_input.rs @@ -406,6 +406,7 @@ impl RenderOnce for TextInput { move |_, window, cx| { state.update(cx, |state, cx| { state.clean(window, cx); + state.focus(window, cx); }) } }))