From 0e34470a40ca573bfe1ab04d47f32456955c33dc Mon Sep 17 00:00:00 2001 From: temportalflux Date: Sun, 21 Jun 2026 19:43:03 -0400 Subject: [PATCH] add stubs for allowing the user to provide their own storage mediums --- .../src/editable_text/input_element.rs | 5 +++++ .../gpui_elements/src/editable_text/storage.rs | 16 ++++++++++++++-- .../src/editable_text/text_area_element.rs | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/crates/gpui_elements/src/editable_text/input_element.rs b/crates/gpui_elements/src/editable_text/input_element.rs index 740eebaa2e..3bc0cbf85f 100644 --- a/crates/gpui_elements/src/editable_text/input_element.rs +++ b/crates/gpui_elements/src/editable_text/input_element.rs @@ -41,6 +41,11 @@ impl TextInputElement { self.placeholder = Some(text.into()); self } + + pub fn with_storage(mut self, fn_init: impl Into) -> Self { + self.init_storage = fn_init.into(); + self + } } impl InteractiveElement for TextInputElement { diff --git a/crates/gpui_elements/src/editable_text/storage.rs b/crates/gpui_elements/src/editable_text/storage.rs index 5da6debeee..ee4c8ff061 100644 --- a/crates/gpui_elements/src/editable_text/storage.rs +++ b/crates/gpui_elements/src/editable_text/storage.rs @@ -14,9 +14,21 @@ pub enum TextBoundary { } #[derive(Clone, Default)] -pub(super) struct InitStorage(Option Box>>); +pub struct InitStorage(Option Box>>); + +// TODO: Doesnt yet compile in practice "implementation of Fn is not general enough" +// InitStorage::from(|_cx| Box::new(StringStorage::default()) as Box); +impl From for InitStorage +where + F: 'static + for<'app> Fn(&'app mut App) -> Box, +{ + fn from(value: F) -> Self { + Self(Some(Rc::new(value))) + } +} + impl InitStorage { - pub fn exec(&self, cx: &mut App) -> Box { + pub(super) fn exec(&self, cx: &mut App) -> Box { match &self.0 { None => Box::new(StringStorage::default()), Some(init) => (*init)(cx), diff --git a/crates/gpui_elements/src/editable_text/text_area_element.rs b/crates/gpui_elements/src/editable_text/text_area_element.rs index 3c0293ab4c..a9fe9120dc 100644 --- a/crates/gpui_elements/src/editable_text/text_area_element.rs +++ b/crates/gpui_elements/src/editable_text/text_area_element.rs @@ -40,6 +40,11 @@ impl TextAreaElement { self.placeholder = Some(text.into()); self } + + pub fn with_storage(mut self, fn_init: impl Into) -> Self { + self.init_storage = fn_init.into(); + self + } } impl InteractiveElement for TextAreaElement {