diff --git a/crates/gpui_elements/src/editable_text.rs b/crates/gpui_elements/src/editable_text.rs index 4664fa4f2f..d46021f3c2 100644 --- a/crates/gpui_elements/src/editable_text.rs +++ b/crates/gpui_elements/src/editable_text.rs @@ -13,13 +13,3 @@ pub use shared_state::*; pub use storage::*; pub use text_area_element::*; pub use text_area_state::*; - -#[allow(dead_code)] -fn make_input(_app: &mut gpui::App) -> impl gpui::IntoElement { - input(0) -} - -#[allow(dead_code)] -fn make_textarea(_app: &mut gpui::App) -> impl gpui::IntoElement { - text_area(0) -} diff --git a/crates/gpui_elements/src/editable_text/actions.rs b/crates/gpui_elements/src/editable_text/actions.rs index 42f15753cb..18e2e9f094 100644 --- a/crates/gpui_elements/src/editable_text/actions.rs +++ b/crates/gpui_elements/src/editable_text/actions.rs @@ -270,6 +270,7 @@ pub(super) trait EditableInputActionElement: super::StateBackedElement { state.insert_tab(action, window, cx) }); self.register_action(init_props.clone(), |state, action, window, cx| { + println!("backspace"); state.backspace(action, window, cx) }); self.register_action(init_props.clone(), |state, action, window, cx| { diff --git a/crates/gpui_elements/src/editable_text/input_element.rs b/crates/gpui_elements/src/editable_text/input_element.rs index e17bc65332..72e8a42787 100644 --- a/crates/gpui_elements/src/editable_text/input_element.rs +++ b/crates/gpui_elements/src/editable_text/input_element.rs @@ -14,9 +14,8 @@ use smallvec::SmallVec; use std::{ops::Range, sync::Arc}; #[track_caller] -pub fn input(id: impl Into) -> TextInputElement { +pub fn input() -> TextInputElement { let mut this = TextInputElement { - id: id.into(), placeholder: None, interactivity: Interactivity::new(), init_storage: InitStorage::default(), @@ -28,7 +27,6 @@ pub fn input(id: impl Into) -> TextInputElement { // TODO: Disabled flag/state? pub struct TextInputElement { - id: ElementId, placeholder: Option, interactivity: Interactivity, init_storage: InitStorage, @@ -56,10 +54,11 @@ impl IntoElement for TextInputElement { impl EditableInputActionElement for TextInputElement {} impl super::StateBackedElement for TextInputElement { type State = TextInputState; - type InitProps = (ElementId, InitStorage); + type InitProps = (Option, InitStorage); fn init_props(&self) -> Self::InitProps { - (self.id.clone(), self.init_storage.clone()) + let element_id = self.interactivity.element_id.clone(); + (element_id, self.init_storage.clone()) } fn get_or_init_state( @@ -69,7 +68,12 @@ impl super::StateBackedElement for TextInputElement { ) -> Entity { // Get the state from the app using the element's id as the key. // If it doesnt exist, initialize a new state with the user's desired storage medium. - window.use_keyed_state(init_props.0.clone(), cx, |_window, cx| { + // TODO: how to best garuntee an element id? + let element_id = init_props + .0 + .clone() + .expect("user MUST assign an element id"); + window.use_keyed_state(element_id, cx, |_window, cx| { TextInputState::new(init_props.1.exec(cx), cx) }) } diff --git a/crates/gpui_elements/src/editable_text/input_state.rs b/crates/gpui_elements/src/editable_text/input_state.rs index 3269d76439..c8e75945b9 100644 --- a/crates/gpui_elements/src/editable_text/input_state.rs +++ b/crates/gpui_elements/src/editable_text/input_state.rs @@ -330,7 +330,9 @@ impl<'app> EditableTextActionHandler<'app> for TextInputState { window: &mut Window, cx: &mut Self::Context, ) { - let character_pos = self.internal.caret_pos(); // TODO: Should be index_for_pixel_point + let character_pos = self + .internal + .index_for_pixel_point(text_position, window.line_height()); self.internal.on_mouse_down( text_position, character_pos, @@ -354,10 +356,12 @@ impl<'app> EditableTextActionHandler<'app> for TextInputState { &mut self, _event: &gpui::MouseMoveEvent, text_position: Point, - _w: &mut Window, + window: &mut Window, cx: &mut Self::Context, ) { - let character_pos = self.internal.caret_pos(); // TODO: Should be index_for_pixel_point + let character_pos = self + .internal + .index_for_pixel_point(text_position, window.line_height()); self.internal.on_mouse_move(character_pos, cx); } } diff --git a/crates/gpui_elements/src/editable_text/text_area_state.rs b/crates/gpui_elements/src/editable_text/text_area_state.rs index 66e95d890d..d3f13aa116 100644 --- a/crates/gpui_elements/src/editable_text/text_area_state.rs +++ b/crates/gpui_elements/src/editable_text/text_area_state.rs @@ -321,7 +321,9 @@ impl<'app> EditableTextActionHandler<'app> for TextAreaState { window: &mut Window, cx: &mut Self::Context, ) { - let character_pos = self.internal.caret_pos(); // TODO: Should be index_for_pixel_point + let character_pos = self + .internal + .index_for_pixel_point(text_position, window.line_height()); self.internal.on_mouse_down( text_position, character_pos, @@ -345,10 +347,12 @@ impl<'app> EditableTextActionHandler<'app> for TextAreaState { &mut self, _event: &gpui::MouseMoveEvent, text_position: Point, - _w: &mut Window, + window: &mut Window, cx: &mut Self::Context, ) { - let character_pos = self.internal.caret_pos(); // TODO: Should be index_for_pixel_point + let character_pos = self + .internal + .index_for_pixel_point(text_position, window.line_height()); self.internal.on_mouse_move(character_pos, cx); } }