From 318cb784b2e7fbaca99504d879a208a18590c97c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 13 Nov 2023 10:17:52 +0100 Subject: [PATCH] Fix panic when calling `with_key_dispatch` recursively Co-Authored-By: Thorsten --- crates/gpui2/src/window.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 15a59253e7..3da2664f79 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -1889,18 +1889,18 @@ impl<'a, V: 'static> ViewContext<'a, V> { focus_handle: Option, f: impl FnOnce(Option, &mut Self) -> R, ) -> R { - let mut old_dispatcher = self.window.previous_frame.key_dispatcher.take().unwrap(); - let mut current_dispatcher = self.window.current_frame.key_dispatcher.take().unwrap(); + let window = &mut self.window; + let old_dispatcher = window.previous_frame.key_dispatcher.as_mut().unwrap(); + let current_dispatcher = window.current_frame.key_dispatcher.as_mut().unwrap(); - current_dispatcher.push_node(context, &mut old_dispatcher); + current_dispatcher.push_node(context, old_dispatcher); if let Some(focus_handle) = focus_handle.as_ref() { current_dispatcher.make_focusable(focus_handle.id); } let result = f(focus_handle, self); - current_dispatcher.pop_node(); - self.window.previous_frame.key_dispatcher = Some(old_dispatcher); - self.window.current_frame.key_dispatcher = Some(current_dispatcher); + let current_dispatcher = self.window.current_frame.key_dispatcher.as_mut().unwrap(); + current_dispatcher.pop_node(); result }