diff --git a/crates/ui/src/input/state.rs b/crates/ui/src/input/state.rs index ecbfdfbf..728ae15a 100644 --- a/crates/ui/src/input/state.rs +++ b/crates/ui/src/input/state.rs @@ -665,12 +665,27 @@ impl InputState { self.replace_text_in_range(Some(range), &text, window, cx); } + /// Set with disabled mode. + /// + /// See also: [`Self::set_disabled`], [`Self::is_disabled`]. + pub fn disabled(mut self, disabled: bool) -> Self { + self.disabled = disabled; + self + } + /// Set the disabled state of the input field. + /// + /// See also: [`Self::disabled`], [`Self::is_disabled`]. pub fn set_disabled(&mut self, disabled: bool, _: &mut Window, cx: &mut Context) { self.disabled = disabled; cx.notify(); } + /// Return is the input field is disabled. + pub fn is_disabled(&self) -> bool { + self.disabled + } + /// Set with password masked state. pub fn masked(mut self, masked: bool) -> Self { self.masked = masked; @@ -734,10 +749,6 @@ impl InputState { self.mask_pattern.unmask(&self.text).into() } - pub fn disabled(&self) -> bool { - self.disabled - } - /// Focus the input field. pub fn focus(&self, window: &mut Window, _: &mut Context) { self.focus_handle.focus(window); diff --git a/crates/ui/src/inspector.rs b/crates/ui/src/inspector.rs index f86d043f..bec90a0e 100644 --- a/crates/ui/src/inspector.rs +++ b/crates/ui/src/inspector.rs @@ -67,11 +67,10 @@ impl DivInspector { }; let input_state = cx.new(|cx| { - let mut state = InputState::new(window, cx) + InputState::new(window, cx) .code_editor(Some("json"), theme) - .line_number(false); - state.set_disabled(true, window, cx); - state + .line_number(false) + .disabled(true) }); Self {