From 6ebe87025b110c0eda037e574bb037f156683a58 Mon Sep 17 00:00:00 2001 From: temportalflux Date: Mon, 15 Jun 2026 19:50:54 -0400 Subject: [PATCH] mocking out cursor event interop --- crates/gpui_elements/src/input.rs | 12 ++++++++++++ crates/gpui_elements/src/input/cursor.rs | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/crates/gpui_elements/src/input.rs b/crates/gpui_elements/src/input.rs index a0d130d737..2c83d493c7 100644 --- a/crates/gpui_elements/src/input.rs +++ b/crates/gpui_elements/src/input.rs @@ -17,3 +17,15 @@ pub(self) use history::*; pub use layout::*; pub use state::*; pub use storage::*; + +#[allow(dead_code)] +fn make_element(app: &mut gpui::App) -> impl gpui::IntoElement { + use gpui::AppContext; + let state = app.new(|cx| InputState::new(cx)); + let cursor = app.new(|cx| { + let mut cursor = Cursor::new(None); + cursor.subscribe_to(&state, cx); + cursor + }); + input(&state, app).cursor(cursor) +} diff --git a/crates/gpui_elements/src/input/cursor.rs b/crates/gpui_elements/src/input/cursor.rs index 258776639b..0f094c9223 100644 --- a/crates/gpui_elements/src/input/cursor.rs +++ b/crates/gpui_elements/src/input/cursor.rs @@ -1,6 +1,12 @@ -use gpui::{Bounds, Context, Element, Hsla, IntoElement, Pixels, Point, Render}; +use gpui::{ + Bounds, Context, Element, Entity, EventEmitter, Hsla, IntoElement, Pixels, Point, Render, + Subscription, +}; +use smallvec::SmallVec; use std::time::Duration; +use crate::input::CursorTrigger; + /// Default interval for cursor blinking. pub const DEFAULT_BLINK_INTERVAL: Duration = Duration::from_millis(500); @@ -17,6 +23,8 @@ pub struct Cursor { was_focused: bool, point: Point, height: Pixels, + #[allow(dead_code)] + subscriptions: SmallVec<[Subscription; 2]>, } impl Cursor { @@ -33,6 +41,7 @@ impl Cursor { was_focused: false, point: Point::default(), height: Pixels::ZERO, + subscriptions: SmallVec::new(), } } @@ -41,6 +50,19 @@ impl Cursor { self } + pub fn subscribe_to(&mut self, emitter: &Entity, cx: &mut Context) + where + E: EventEmitter, + { + let handle = cx.subscribe(emitter, |cursor, _emitter, event, cx| match event { + CursorTrigger::PauseBlinkingForUserAction => { + cursor.pause_blinking(cx); + cx.notify(); + } + }); + self.subscriptions.push(handle); + } + /// Returns whether the cursor should currently be rendered. pub fn visible(&self) -> bool { self.visible