From 7c19650a4065eb8343d5e578c560ffb2aaa8fe98 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Thu, 7 Dec 2023 12:37:07 -0500 Subject: [PATCH] Remove when_else Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/feedback2/src/feedback_modal.rs | 22 +++++++++++++--------- crates/gpui2/src/element.rs | 18 ------------------ crates/ui2/src/components/keybinding.rs | 12 +++++++----- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/crates/feedback2/src/feedback_modal.rs b/crates/feedback2/src/feedback_modal.rs index 68fbcfb3a3..583d31ce5d 100644 --- a/crates/feedback2/src/feedback_modal.rs +++ b/crates/feedback2/src/feedback_modal.rs @@ -319,10 +319,12 @@ impl Render for FeedbackModal { "Characters: {}", characters_remaining )) - .when_else( - valid_character_count, - |this| this.color(Color::Success), - |this| this.color(Color::Error) + .color( + if valid_character_count { + Color::Success + } else { + Color::Error + } ) ), ) @@ -349,11 +351,13 @@ impl Render for FeedbackModal { .color(Color::Muted) // TODO: replicate this logic when clicking outside the modal // TODO: Will require somehow overriding the modal dismal default behavior - .when_else( - has_feedback, - |this| this.on_click(dismiss_prompt), - |this| this.on_click(dismiss) - ) + .map(|this| { + if has_feedback { + this.on_click(dismiss_prompt) + } else { + this.on_click(dismiss) + } + }) ) .child( Button::new("send_feedback", submit_button_text) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index a67276b0bc..226a477012 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -69,24 +69,6 @@ pub trait IntoElement: Sized { self.map(|this| if condition { then(this) } else { this }) } - fn when_else( - self, - condition: bool, - then: impl FnOnce(Self) -> Self, - otherwise: impl FnOnce(Self) -> Self, - ) -> Self - where - Self: Sized, - { - self.map(|this| { - if condition { - then(this) - } else { - otherwise(this) - } - }) - } - fn when_some(self, option: Option, then: impl FnOnce(Self, T) -> Self) -> Self where Self: Sized, diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index 29586fd194..8314f607fe 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -98,11 +98,13 @@ impl RenderOnce for Key { div() .py_0() - .when_else( - single_char, - |el| el.w(rems(14. / 16.)).flex().flex_none().justify_center(), - |el| el.px_0p5(), - ) + .map(|this| { + if single_char { + this.w(rems(14. / 16.)).flex().flex_none().justify_center() + } else { + this.px_0p5() + } + }) .h(rems(14. / 16.)) .text_ui() .line_height(relative(1.))