From 4558b504fc08d1233c26904a2b543f8f159734dc Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 10 Feb 2023 11:41:03 -0800 Subject: [PATCH] Merge pull request #2154 from zed-industries/fix-tooltip-crash Don't render tooltip keystroke label if there's no focused view --- crates/gpui/src/elements/tooltip.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/gpui/src/elements/tooltip.rs b/crates/gpui/src/elements/tooltip.rs index e79eefc5f4b5949a78282f14362451071ad2794f..562f12295c4a3cd0dbbba28d46301de41f212ef7 100644 --- a/crates/gpui/src/elements/tooltip.rs +++ b/crates/gpui/src/elements/tooltip.rs @@ -61,7 +61,7 @@ impl Tooltip { ) -> Self { struct ElementState(Tag); struct MouseEventHandlerState(Tag); - let focused_view_id = cx.focused_view_id(cx.window_id).unwrap(); + let focused_view_id = cx.focused_view_id(cx.window_id); let state_handle = cx.default_element_state::, Rc>(id); let state = state_handle.read(cx).clone(); @@ -132,7 +132,7 @@ impl Tooltip { pub fn render_tooltip( window_id: usize, - focused_view_id: usize, + focused_view_id: Option, text: String, style: TooltipStyle, action: Option>, @@ -149,18 +149,18 @@ impl Tooltip { text.flex(1., false).aligned().boxed() } }) - .with_children(action.map(|action| { + .with_children(action.and_then(|action| { let keystroke_label = KeystrokeLabel::new( window_id, - focused_view_id, + focused_view_id?, action, style.keystroke.container, style.keystroke.text, ); if measure { - keystroke_label.boxed() + Some(keystroke_label.boxed()) } else { - keystroke_label.aligned().boxed() + Some(keystroke_label.aligned().boxed()) } })) .contained()