From 0fd220366538ede11d54e1d0162ea6c07d335f5f Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Mon, 10 Feb 2025 20:47:09 +0100 Subject: [PATCH] context_menu: Use `when` instead of if-block (#24566) See https://github.com/zed-industries/zed/pull/24562#issuecomment-2648343416 . Should have just added that to my original comment btw - sorry! CC @danilo-leal Release Notes: - N/A --- crates/ui/src/components/context_menu.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/ui/src/components/context_menu.rs b/crates/ui/src/components/context_menu.rs index b827a576673f7ffefc4421c7791237fcce13679f..2ebaa551052ffecdea235d179d94f47c742c2a67 100644 --- a/crates/ui/src/components/context_menu.rs +++ b/crates/ui/src/components/context_menu.rs @@ -671,18 +671,16 @@ impl Render for ContextMenu { .when_some( *toggle, |list_item, (position, toggled)| { - let contents = if toggled { + let contents = div().flex_none().child( Icon::new(IconName::Check) .color(Color::Accent) .size(*icon_size) ) - } else { - div().flex_none().child( - Icon::new(IconName::Check) - .size(*icon_size) - ).invisible() - }; + .when(!toggled, |contents| + contents.invisible() + ); + match position { IconPosition::Start => { list_item