From 97df4efd46108b58a79609a42509f05cc3eb99f2 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 13 Oct 2025 11:15:32 +0800 Subject: [PATCH] input: Fix `set_value` when Input is disabled. (#1362) Close #1350 --- crates/story/src/input_story.rs | 19 +++++++++++++------ crates/ui/src/input/state.rs | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/story/src/input_story.rs b/crates/story/src/input_story.rs index e7965520..d7ac9734 100644 --- a/crates/story/src/input_story.rs +++ b/crates/story/src/input_story.rs @@ -1,6 +1,6 @@ use gpui::{ - div, App, AppContext as _, Context, Entity, InteractiveElement, IntoElement, - ParentElement as _, Render, Styled, Subscription, Window, + App, AppContext as _, Context, Entity, InteractiveElement, IntoElement, ParentElement as _, + Render, Styled, Subscription, Window, div, }; use crate::section; @@ -121,13 +121,20 @@ impl InputStory { &mut self, state: &Entity, event: &InputEvent, - _window: &mut Window, - _cx: &mut Context, + window: &mut Window, + cx: &mut Context, ) { match event { InputEvent::Change => { - let text = state.read(_cx).value(); - println!("Change: {}", text) + let text = state.read(cx).value(); + if state == &self.input2 { + println!("Set disabled value: {}", text); + self.disabled_input.update(cx, |this, cx| { + this.set_value(text, window, cx); + }) + } else { + println!("Change: {}", text) + } } InputEvent::PressEnter { secondary } => println!("PressEnter secondary: {}", secondary), InputEvent::Focus => println!("Focus"), diff --git a/crates/ui/src/input/state.rs b/crates/ui/src/input/state.rs index 5bb1d2b7..11d10405 100644 --- a/crates/ui/src/input/state.rs +++ b/crates/ui/src/input/state.rs @@ -637,6 +637,7 @@ impl InputState { ) { self.history.ignore = true; let was_disabled = self.disabled; + self.disabled = false; self.replace_text(value, window, cx); self.disabled = was_disabled; self.history.ignore = false;