From 31e906d068670dbf4d8635ae8635284b573242be Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 21 Apr 2023 16:19:51 +0200 Subject: [PATCH] Avoid double borrow of views on `up` and `up_out` in `DragAndDrop` Co-Authored-By: Nathan Sobo --- crates/drag_and_drop/src/drag_and_drop.rs | 8 ++++---- crates/gpui/src/app.rs | 4 ++++ crates/gpui/src/app/window.rs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/drag_and_drop/src/drag_and_drop.rs b/crates/drag_and_drop/src/drag_and_drop.rs index 1a959b9a34..c6837eb559 100644 --- a/crates/drag_and_drop/src/drag_and_drop.rs +++ b/crates/drag_and_drop/src/drag_and_drop.rs @@ -209,7 +209,7 @@ impl DragAndDrop { ) .with_cursor_style(CursorStyle::Arrow) .on_up(MouseButton::Left, |_, _, cx| { - cx.defer(|_, cx| { + cx.window_context().defer(|cx| { cx.update_global::(|this, cx| { this.finish_dragging(cx) }); @@ -217,7 +217,7 @@ impl DragAndDrop { cx.propagate_event(); }) .on_up_out(MouseButton::Left, |_, _, cx| { - cx.defer(|_, cx| { + cx.window_context().defer(|cx| { cx.update_global::(|this, cx| { this.finish_dragging(cx) }); @@ -244,14 +244,14 @@ impl DragAndDrop { .boxed() }) .on_up(MouseButton::Left, |_, _, cx| { - cx.defer(|_, cx| { + cx.window_context().defer(|cx| { cx.update_global::(|this, _| { this.currently_dragged = None; }); }); }) .on_up_out(MouseButton::Left, |_, _, cx| { - cx.defer(|_, cx| { + cx.window_context().defer(|cx| { cx.update_global::(|this, _| { this.currently_dragged = None; }); diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 3e311aa50c..8ab8bf31e2 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -2954,6 +2954,10 @@ impl<'a, 'b, 'c, V: View> ViewContext<'a, 'b, 'c, V> { } } + pub fn window_context(&mut self) -> &mut WindowContext<'a, 'b> { + &mut self.window_context + } + pub fn handle(&self) -> ViewHandle { ViewHandle::new( self.window_id, diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rs index b429c70390..d19b5c8510 100644 --- a/crates/gpui/src/app/window.rs +++ b/crates/gpui/src/app/window.rs @@ -174,7 +174,7 @@ impl UpdateView for WindowContext<'_, '_> { &mut cx, ) }) - .unwrap() + .expect("view is already on the stack") } }