History

Remove when_else

Joseph T. Lyons committed 2 years ago

Commit 7c196501 parent 393be3c3 files · +20 −32Browse files

Unified · Split

3 files
  1. crates/feedback2/src/feedback_modal.rs +13 −9
  2. crates/gpui2/src/element.rs +0 −18
  3. crates/ui2/src/components/keybinding.rs +7 −5
crates/feedback2/src/feedback_modal.rs+13−9
@@ -319,10 +319,12 @@ impl Render for FeedbackModal { · 318 unmodified lines
319319 "Characters: {}",
320320 characters_remaining
321321 ))
322− .when_else(
323− valid_character_count,
324− |this| this.color(Color::Success),
325− |this| this.color(Color::Error)
322+ .color(
323+ if valid_character_count {
324+ Color::Success
325+ } else {
326+ Color::Error
327+ }
326328 )
327329 ),
328330 )
@@ -349,11 +351,13 @@ impl Render for FeedbackModal { · 20 unmodified lines
349351 .color(Color::Muted)
350352 // TODO: replicate this logic when clicking outside the modal
351353 // TODO: Will require somehow overriding the modal dismal default behavior
352− .when_else(
353− has_feedback,
354− |this| this.on_click(dismiss_prompt),
355− |this| this.on_click(dismiss)
356− )
354+ .map(|this| {
355+ if has_feedback {
356+ this.on_click(dismiss_prompt)
357+ } else {
358+ this.on_click(dismiss)
359+ }
360+ })
357361 )
358362 .child(
359363 Button::new("send_feedback", submit_button_text)
crates/gpui2/src/element.rs+0−18
@@ -69,24 +69,6 @@ pub trait IntoElement: Sized { · 68 unmodified lines
6969 self.map(|this| if condition { then(this) } else { this })
7070 }
7171
72− fn when_else(
73− self,
74− condition: bool,
75− then: impl FnOnce(Self) -> Self,
76− otherwise: impl FnOnce(Self) -> Self,
77− ) -> Self
78− where
79− Self: Sized,
80− {
81− self.map(|this| {
82− if condition {
83− then(this)
84− } else {
85− otherwise(this)
86− }
87− })
88− }
89−
9072 fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self
9173 where
9274 Self: Sized,
crates/ui2/src/components/keybinding.rs+7−5
@@ -98,11 +98,13 @@ impl RenderOnce for Key { · 97 unmodified lines
9898
9999 div()
100100 .py_0()
101− .when_else(
102− single_char,
103− |el| el.w(rems(14. / 16.)).flex().flex_none().justify_center(),
104− |el| el.px_0p5(),
105− )
101+ .map(|this| {
102+ if single_char {
103+ this.w(rems(14. / 16.)).flex().flex_none().justify_center()
104+ } else {
105+ this.px_0p5()
106+ }
107+ })
106108 .h(rems(14. / 16.))
107109 .text_ui()
108110 .line_height(relative(1.))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t