diff --git a/crates/workspace/src/dock/toggle_dock_button.rs b/crates/workspace/src/dock/toggle_dock_button.rs index babd08298a3eadb1599fbcad5190a5ab8ad6ba11..bf851839383b67f651c0d192c9b1e51c9a05443c 100644 --- a/crates/workspace/src/dock/toggle_dock_button.rs +++ b/crates/workspace/src/dock/toggle_dock_button.rs @@ -67,9 +67,17 @@ impl View for ToggleDockButton { } }) .with_cursor_style(CursorStyle::PointingHand) - .on_up(MouseButton::Left, move |event, _, cx| { + .on_up(MouseButton::Left, move |event, this, cx| { let drop_index = dock_pane.read(cx).items_len() + 1; - handle_dropped_item(event, &dock_pane.downgrade(), drop_index, false, None, cx); + handle_dropped_item( + event, + this.workspace.clone(), + &dock_pane.downgrade(), + drop_index, + false, + None, + cx, + ); }); if dock_position.is_visible() { diff --git a/crates/workspace/src/pane/dragged_item_receiver.rs b/crates/workspace/src/pane/dragged_item_receiver.rs index 63eac1ccb9c89d28d59917e4b286dbfbb572166f..3cd26697bc55994d0dec0b00777adfe7f087ee23 100644 --- a/crates/workspace/src/pane/dragged_item_receiver.rs +++ b/crates/workspace/src/pane/dragged_item_receiver.rs @@ -69,9 +69,18 @@ where })) }) .on_up(MouseButton::Left, { - move |event, _, cx| { + move |event, pane, cx| { + let workspace = pane.workspace.clone(); let pane = cx.weak_handle(); - handle_dropped_item(event, &pane, drop_index, allow_same_pane, split_margin, cx); + handle_dropped_item( + event, + workspace, + &pane, + drop_index, + allow_same_pane, + split_margin, + cx, + ); cx.notify(); } }) @@ -94,6 +103,7 @@ where pub fn handle_dropped_item( event: MouseUp, + workspace: WeakViewHandle, pane: &WeakViewHandle, index: usize, allow_same_pane: bool, @@ -141,12 +151,14 @@ pub fn handle_dropped_item( if pane != &from || allow_same_pane { let pane = pane.clone(); cx.window_context().defer(move |cx| { - if let Some((from, to)) = from.upgrade(cx).zip(pane.upgrade(cx)) { - if let Some(workspace) = from.read(cx).workspace.upgrade(cx) { - workspace.update(cx, |workspace, cx| { - Pane::move_item(workspace, from, to, item_id, index, cx); - }) - } + if let Some(((workspace, from), to)) = workspace + .upgrade(cx) + .zip(from.upgrade(cx)) + .zip(pane.upgrade(cx)) + { + workspace.update(cx, |workspace, cx| { + Pane::move_item(workspace, from, to, item_id, index, cx); + }) } }); } else { @@ -156,18 +168,16 @@ pub fn handle_dropped_item( Action::Open(project_entry) => { let pane = pane.clone(); cx.window_context().defer(move |cx| { - if let Some(pane) = pane.upgrade(cx) { - if let Some(workspace) = pane.read(cx).workspace.upgrade(cx) { - workspace.update(cx, |workspace, cx| { - if let Some(path) = - workspace.project.read(cx).path_for_entry(project_entry, cx) - { - workspace - .open_path(path, Some(pane.downgrade()), true, cx) - .detach_and_log_err(cx); - } - }); - } + if let Some(workspace) = workspace.upgrade(cx) { + workspace.update(cx, |workspace, cx| { + if let Some(path) = + workspace.project.read(cx).path_for_entry(project_entry, cx) + { + workspace + .open_path(path, Some(pane), true, cx) + .detach_and_log_err(cx); + } + }); } }); }