From aa5db4036e288589092874f92918b3a115fc063a Mon Sep 17 00:00:00 2001 From: Nessar Date: Fri, 27 Nov 2026 11:53:40 +0100 Subject: [PATCH 1/2] Give a text field the keyboard on a click in its padding or border (#138) gpui-component's Input frame tracks its own focus handle, apart from the editor's: a click off the text line focused the frame and typing went nowhere. One app-side wrapper focuses the field's state instead. Co-Authored-By: Claude Opus 5.5 --- crates/app/src/input_frame.rs | 21 +++++++++++++++++ crates/app/src/main.rs | 1 + crates/app/src/page/champ_select/render.rs | 11 +++++---- crates/app/src/page/friends.rs | 9 +++++--- crates/app/src/page/home.rs | 12 ++++++---- crates/app/src/page/matches/filters.rs | 9 +++++--- crates/app/src/page/statistics.rs | 11 +++++---- crates/app/src/page/tests/home.rs | 26 ++++++++++++++++++++++ crates/app/src/settings.rs | 6 ++++- 9 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 crates/app/src/input_frame.rs diff --git a/crates/app/src/input_frame.rs b/crates/app/src/input_frame.rs new file mode 100644 index 0000000..44c86e7 --- /dev/null +++ b/crates/app/src/input_frame.rs @@ -0,0 +1,21 @@ +//! A click anywhere in a text field's frame gives it the keyboard. +//! +//! gpui-component's `Input` tracks a focus handle of its own on the frame, apart from the +//! editor's: a click in the padding or the border focused the frame, and typing wrote nothing. + +use gpui_kit::component::input::{Input, InputState}; +use gpui_kit::*; + +/// `input` in a wrapper that focuses `state` on a left click the editor did not take (the +/// padding, the border). The text line and the buttons run first and keep their own click: the +/// wrapper does nothing once the editor has the focus. Size the wrapper, not the `Input`. +pub fn input_frame(state: &Entity, input: Input) -> Div { + let state = state.clone(); + div() + .on_mouse_down(MouseButton::Left, move |_, window, cx| { + if !state.read(cx).focus_handle(cx).is_focused(window) { + state.update(cx, |state, cx| state.focus(window, cx)); + } + }) + .child(input) +} diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index f2670b8..ba9c136 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -7,6 +7,7 @@ mod card_images; mod card_lift; mod card_order; mod champion_table; +mod input_frame; mod local_time; mod logon; mod minimized; diff --git a/crates/app/src/page/champ_select/render.rs b/crates/app/src/page/champ_select/render.rs index cdf9c6c..fa79e28 100644 --- a/crates/app/src/page/champ_select/render.rs +++ b/crates/app/src/page/champ_select/render.rs @@ -1,5 +1,6 @@ use super::UNKNOWN_ANVIL; use crate::card_grid::MAX_WIDTH; +use crate::input_frame::input_frame; use crate::page::{ Page, home::{StatsNotice, count_badge, notice_line}, @@ -191,10 +192,12 @@ impl Page { .gap_x_3() .gap_y_2() .child( - Input::new(&self.others_search_input) - .cleanable(true) - .w(px(260.)) - .min_w(px(150.)), + input_frame( + &self.others_search_input, + Input::new(&self.others_search_input).cleanable(true), + ) + .w(px(260.)) + .min_w(px(150.)), ) .child(self.sort_selector(cx)), ) diff --git a/crates/app/src/page/friends.rs b/crates/app/src/page/friends.rs index 64e3262..ddeb10f 100644 --- a/crates/app/src/page/friends.rs +++ b/crates/app/src/page/friends.rs @@ -3,6 +3,7 @@ //! Matches are fetched when it is added, when it is chosen in the selector and on « Actualiser ». use super::{AccountItem, AccountList, Page, RELOAD_EVERY, SettingsRequested}; +use crate::input_frame::input_frame; use crate::text::friend_sync_line; use crate::worker::{spawn_add_friend, spawn_friend_import}; use arena_tracker_core::{AddFriendError, AddedFriend, SyncProgress}; @@ -304,9 +305,11 @@ impl Page { .gap_y_2() .on_action(cx.listener(|page, _: &Escape, _, cx| page.close_friend_field(cx))) .child( - div() - .w(px(260.)) - .child(gpui_kit::component::input::Input::new(&self.friends.input)), + input_frame( + &self.friends.input, + gpui_kit::component::input::Input::new(&self.friends.input), + ) + .w(px(260.)), ) .child( Button::new("friend-cancel") diff --git a/crates/app/src/page/home.rs b/crates/app/src/page/home.rs index 17bee79..9f3b75f 100644 --- a/crates/app/src/page/home.rs +++ b/crates/app/src/page/home.rs @@ -18,6 +18,7 @@ pub(in crate::page) use content::{BannerContent, Line}; use super::{Page, shown}; use crate::card_grid::MAX_WIDTH; +use crate::input_frame::input_frame; use crate::theme::heading; /// The filters on offer, whatever the Season. @@ -246,10 +247,13 @@ impl Page { .items_center() .gap_3() .child( - Input::new(&self.home_search_input) - .cleanable(true) - .w(px(260.)) - .min_w(px(150.)), + input_frame( + &self.home_search_input, + Input::new(&self.home_search_input).cleanable(true), + ) + .w(px(260.)) + .min_w(px(150.)) + .debug_selector(|| "home-search".into()), ) .child( TabBar::new("home-filter") diff --git a/crates/app/src/page/matches/filters.rs b/crates/app/src/page/matches/filters.rs index fd2e577..d11f706 100644 --- a/crates/app/src/page/matches/filters.rs +++ b/crates/app/src/page/matches/filters.rs @@ -15,6 +15,7 @@ use gpui_kit::*; use super::list::{MatchRow, Outcome}; use super::shown::Champions; +use crate::input_frame::input_frame; use crate::page::{Page, Tab}; use crate::text::ordinal; use crate::worker::MatchEntry; @@ -226,9 +227,11 @@ impl Page { ) .child(self.placement_control(cx)) .child( - Input::new(&self.matches.filters.input) - .cleanable(true) - .w_full(), + input_frame( + &self.matches.filters.input, + Input::new(&self.matches.filters.input).cleanable(true), + ) + .w_full(), ) } diff --git a/crates/app/src/page/statistics.rs b/crates/app/src/page/statistics.rs index fb08b0b..772eb4f 100644 --- a/crates/app/src/page/statistics.rs +++ b/crates/app/src/page/statistics.rs @@ -13,6 +13,7 @@ use gpui_kit::prelude::FluentBuilder as _; use gpui_kit::*; use super::{Page, Tab as Screen, shown}; +use crate::input_frame::input_frame; use crate::text::{decimal, official_note}; use crate::theme::{heading, surface}; @@ -382,10 +383,12 @@ impl Page { })), ) .child( - Input::new(&self.search_input) - .cleanable(true) - .w(px(260.)) - .min_w(px(150.)), + input_frame( + &self.search_input, + Input::new(&self.search_input).cleanable(true), + ) + .w(px(260.)) + .min_w(px(150.)), ) .into_any_element(), ); diff --git a/crates/app/src/page/tests/home.rs b/crates/app/src/page/tests/home.rs index b2dff3d..7345b07 100644 --- a/crates/app/src/page/tests/home.rs +++ b/crates/app/src/page/tests/home.rs @@ -165,6 +165,32 @@ fn the_counter_keeps_its_total_while_a_search_and_a_filter_reduce_the_list( assert_eq!(counter(cx), "1 / 4 champions validés"); } +#[gpui::test] +fn a_click_in_the_padding_of_the_search_field_gives_it_the_keyboard(cx: &mut TestAppContext) { + use gpui_kit::{Modifiers, point, px}; + let (page, cx) = open_page_in_season(cx); + let cx = &mut { cx }; + show(&page, cx, statistics(0, 3, champions(3))); + draw(cx); + let input = page.read_with(cx, |p, _| p.home_search_input.clone()); + let field = cx.debug_bounds("home-search").unwrap(); + let text = |cx: &mut VisualTestContext| input.read_with(cx, |i, _| i.value().to_string()); + + // Just inside the left border, above the text line: nothing but the frame is there. + cx.simulate_click( + point(field.left() + px(2.), field.top() + px(2.)), + Modifiers::none(), + ); + cx.simulate_input("an"); + assert_eq!(text(cx), "an"); + + // The text line still takes its own click, and the field keeps working. + cx.update(|window, cx| window.blur(cx)); + cx.simulate_click(field.center(), Modifiers::none()); + cx.simulate_input("x"); + assert_eq!(text(cx), "anx"); +} + #[gpui::test] fn the_home_follows_the_season_of_the_statistics_but_not_their_format(cx: &mut TestAppContext) { cx.executor().allow_parking(); diff --git a/crates/app/src/settings.rs b/crates/app/src/settings.rs index f1dabc4..9c1b49a 100644 --- a/crates/app/src/settings.rs +++ b/crates/app/src/settings.rs @@ -10,6 +10,7 @@ use gpui_kit::component::input::{Input, InputEvent, InputState}; use gpui_kit::component::{ActiveTheme as _, StyledExt as _}; use gpui_kit::*; +use crate::input_frame::input_frame; use crate::logon::LogonLaunch; use crate::release::{self, channel}; use crate::tray::{Tray, UNAVAILABLE}; @@ -435,7 +436,10 @@ impl Render for KeyForm { .children((!self.first_launch).then(|| self.preferences(cx))) .children((!self.first_launch).then(|| self.accounts_section(cx))) .child(div().text_color(muted).child(explanation)) - .child(Input::new(&self.input).mask_toggle()) + .child(input_frame( + &self.input, + Input::new(&self.input).mask_toggle(), + )) .children( self.error .clone() From 78cbc87e68b3f09db8f2aa04fe1689dfc25fa812 Mon Sep 17 00:00:00 2001 From: Nessar Date: Fri, 27 Nov 2026 12:13:57 +0100 Subject: [PATCH 2/2] Address review: state that the field buttons also focus the field (#138) Co-Authored-By: Claude Opus 5.5 --- crates/app/src/input_frame.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/app/src/input_frame.rs b/crates/app/src/input_frame.rs index 44c86e7..f83bcfe 100644 --- a/crates/app/src/input_frame.rs +++ b/crates/app/src/input_frame.rs @@ -7,8 +7,10 @@ use gpui_kit::component::input::{Input, InputState}; use gpui_kit::*; /// `input` in a wrapper that focuses `state` on a left click the editor did not take (the -/// padding, the border). The text line and the buttons run first and keep their own click: the -/// wrapper does nothing once the editor has the focus. Size the wrapper, not the `Input`. +/// padding, the border). The text line and the buttons run first and keep their own click, but +/// the field's own buttons (the clear cross, the mask toggle) do not stop the event, so a click +/// on one also focuses the field. The wrapper does nothing once the editor has the focus. Size +/// the wrapper, not the `Input`. pub fn input_frame(state: &Entity, input: Input) -> Div { let state = state.clone(); div()