input: Clean to reset selection and scroll offset. (#1326)

- Focus back to input when click `clean` button.
This commit is contained in:
Jason Lee 2025-10-03 16:11:27 +08:00 committed by GitHub
parent 9754cab4d7
commit a48232cefd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 0 deletions

View file

@ -1512,6 +1512,8 @@ impl InputState {
pub(super) fn clean(&mut self, window: &mut Window, cx: &mut Context<Self>) {
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<Self>) {

View file

@ -406,6 +406,7 @@ impl RenderOnce for TextInput {
move |_, window, cx| {
state.update(cx, |state, cx| {
state.clean(window, cx);
state.focus(window, cx);
})
}
}))