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 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3003930f1
commit
aa5db4036e
9 files changed
+87
-19
No files matched your search
@@ -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<InputState>, 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)
|
||||
}
|
||||
Reference in new issue
Block a user