Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Work with window handles instead of ids in drag code
Nathan Soboda7dc9c880b0
diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex b3703aa64a4..0d398fcce90 100644--- a/crates/command_palette/src/command_palette.rs+++ b/crates/command_palette/src/command_palette.rs@@ -1,8 +1,8 @@use collections::CommandPaletteFilter;use fuzzy::{StringMatch, StringMatchCandidate};use gpui::{- actions, elements::*, keymap_matcher::Keystroke, Action, AppContext, Element, MouseState,- ViewContext,+ actions, elements::*, keymap_matcher::Keystroke, Action, AnyWindowHandle, AppContext, Element,+ MouseState, ViewContext,};use picker::{Picker, PickerDelegate, PickerEvent};use std::cmp;@@ -28,7 +28,7 @@ pub struct CommandPaletteDelegate {pub enum Event {Dismissed,Confirmed {- window_id: usize,+ window: AnyWindowHandle,focused_view_id: usize,action: Box<dyn Action>,},diff --git a/crates/drag_and_drop/src/drag_and_drop.rs b/crates/drag_and_drop/src/drag_and_drop.rsindex 828e7304038..ddfed0c8582 100644--- a/crates/drag_and_drop/src/drag_and_drop.rs+++ b/crates/drag_and_drop/src/drag_and_drop.rs@@ -6,7 +6,7 @@ use gpui::{geometry::{rect::RectF, vector::Vector2F},platform::{CursorStyle, MouseButton},scene::{MouseDown, MouseDrag},- AnyElement, Element, View, ViewContext, WeakViewHandle, WindowContext,+ AnyElement, AnyWindowHandle, Element, View, ViewContext, WeakViewHandle, WindowContext,};const DEAD_ZONE: f32 = 4.;@@ -21,7 +21,7 @@ enum State<V: View> {region: RectF,},Dragging {- window_id: usize,+ window: AnyWindowHandle,position: Vector2F,region_offset: Vector2F,region: RectF,@@ -49,14 +49,14 @@ impl<V: View> Clone for State<V> {region,},State::Dragging {- window_id,+ window,position,region_offset,region,payload,render,} => Self::Dragging {- window_id: window_id.clone(),+ window: window.clone(),position: position.clone(),region_offset: region_offset.clone(),region: region.clone(),@@ -87,16 +87,16 @@ impl<V: View> DragAndDrop<V> {self.containers.insert(handle);}- pub fn currently_dragged<T: Any>(&self, window_id: usize) -> Option<(Vector2F, Rc<T>)> {+ pub fn currently_dragged<T: Any>(&self, window: AnyWindowHandle) -> Option<(Vector2F, Rc<T>)> {self.currently_dragged.as_ref().and_then(|state| {if let State::Dragging {position,payload,- window_id: window_dragged_from,+ window: window_dragged_from,..} = state{- if &window_id != window_dragged_from {+ if &window != window_dragged_from {return None;}@@ -126,9 +126,9 @@ impl<V: View> DragAndDrop<V> {cx: &mut WindowContext,render: Rc<impl 'static + Fn(&T, &mut ViewContext<V>) -> AnyElement<V>>,) {- let window_id = cx.window_id();+ let window = cx.window();cx.update_global(|this: &mut Self, cx| {- this.notify_containers_for_window(window_id, cx);+ this.notify_containers_for_window(window, cx);match this.currently_dragged.as_ref() {Some(&State::Down {@@ -141,7 +141,7 @@ impl<V: View> DragAndDrop<V> {}) => {if (event.position - (region.origin() + region_offset)).length() > DEAD_ZONE {this.currently_dragged = Some(State::Dragging {- window_id,+ window,region_offset,region,position: event.position,@@ -163,7 +163,7 @@ impl<V: View> DragAndDrop<V> {..}) => {this.currently_dragged = Some(State::Dragging {- window_id,+ window,region_offset,region,position: event.position,@@ -188,14 +188,14 @@ impl<V: View> DragAndDrop<V> {State::Down { .. } => None,State::DeadZone { .. } => None,State::Dragging {- window_id,+ window,region_offset,position,region,payload,render,} => {- if cx.window_id() != window_id {+ if cx.window() != window {return None;}@@ -260,27 +260,27 @@ impl<V: View> DragAndDrop<V> {pub fn cancel_dragging<P: Any>(&mut self, cx: &mut WindowContext) {if let Some(State::Dragging {- payload, window_id, ..+ payload, window, ..}) = &self.currently_dragged{if payload.is::<P>() {- let window_id = *window_id;+ let window = *window;self.currently_dragged = Some(State::Canceled);- self.notify_containers_for_window(window_id, cx);+ self.notify_containers_for_window(window, cx);}}}fn finish_dragging(&mut self, cx: &mut WindowContext) {- if let Some(State::Dragging { window_id, .. }) = self.currently_dragged.take() {- self.notify_containers_for_window(window_id, cx);+ if let Some(State::Dragging { window, .. }) = self.currently_dragged.take() {+ self.notify_containers_for_window(window, cx);}}- fn notify_containers_for_window(&mut self, window_id: usize, cx: &mut WindowContext) {+ fn notify_containers_for_window(&mut self, window: AnyWindowHandle, cx: &mut WindowContext) {self.containers.retain(|container| {if let Some(container) = container.upgrade(cx) {- if container.window_id() == window_id {+ if container.window() == window {container.update(cx, |_, cx| cx.notify());}truediff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex df4334a19fc..f7582f1764c 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -1415,7 +1415,7 @@ impl ProjectPanel {if cx.global::<DragAndDrop<Workspace>>()- .currently_dragged::<ProjectEntryId>(cx.window_id())+ .currently_dragged::<ProjectEntryId>(cx.window()).is_some()&& dragged_entry_destination.as_ref()@@ -1459,7 +1459,7 @@ impl ProjectPanel {.on_up(MouseButton::Left, move |_, this, cx| {if let Some((_, dragged_entry)) = cx.global::<DragAndDrop<Workspace>>()- .currently_dragged::<ProjectEntryId>(cx.window_id())+ .currently_dragged::<ProjectEntryId>(cx.window()){this.move_entry(*dragged_entry,@@ -1472,7 +1472,7 @@ impl ProjectPanel {.on_move(move |_, this, cx| {if cx.global::<DragAndDrop<Workspace>>()- .currently_dragged::<ProjectEntryId>(cx.window_id())+ .currently_dragged::<ProjectEntryId>(cx.window()).is_some(){this.dragged_entry_destination = if matches!(kind, EntryKind::File(_)) {diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rsindex 6ad321c735d..d00324cf166 100644--- a/crates/terminal_view/src/terminal_panel.rs+++ b/crates/terminal_view/src/terminal_panel.rs@@ -48,7 +48,7 @@ impl TerminalPanel {fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {let weak_self = cx.weak_handle();let pane = cx.add_view(|cx| {- let window_id = cx.window_id();+ let window = cx.window();let mut pane = Pane::new(workspace.weak_handle(),workspace.project().clone(),@@ -60,7 +60,7 @@ impl TerminalPanel {pane.set_can_navigate(false, cx);pane.on_can_drop(move |drag_and_drop, cx| {drag_and_drop- .currently_dragged::<DraggedItem>(window_id)+ .currently_dragged::<DraggedItem>(window).map_or(false, |(_, item)| {item.handle.act_as::<TerminalView>(cx).is_some()})diff --git a/crates/workspace/src/pane/dragged_item_receiver.rs b/crates/workspace/src/pane/dragged_item_receiver.rsindex 7146ab7b85b..2d3fe8ea832 100644--- a/crates/workspace/src/pane/dragged_item_receiver.rs+++ b/crates/workspace/src/pane/dragged_item_receiver.rs@@ -28,11 +28,11 @@ wherelet drag_and_drop = cx.global::<DragAndDrop<Workspace>>();let drag_position = if (pane.can_drop)(drag_and_drop, cx) {drag_and_drop- .currently_dragged::<DraggedItem>(cx.window_id())+ .currently_dragged::<DraggedItem>(cx.window()).map(|(drag_position, _)| drag_position).or_else(|| {drag_and_drop- .currently_dragged::<ProjectEntryId>(cx.window_id())+ .currently_dragged::<ProjectEntryId>(cx.window()).map(|(drag_position, _)| drag_position)})} else {@@ -91,10 +91,10 @@ wherelet drag_and_drop = cx.global::<DragAndDrop<Workspace>>();if drag_and_drop- .currently_dragged::<DraggedItem>(cx.window_id())+ .currently_dragged::<DraggedItem>(cx.window()).is_some()|| drag_and_drop- .currently_dragged::<ProjectEntryId>(cx.window_id())+ .currently_dragged::<ProjectEntryId>(cx.window()).is_some(){cx.notify();@@ -122,11 +122,11 @@ pub fn handle_dropped_item<V: View>(}let drag_and_drop = cx.global::<DragAndDrop<Workspace>>();let action = if let Some((_, dragged_item)) =- drag_and_drop.currently_dragged::<DraggedItem>(cx.window_id())+ drag_and_drop.currently_dragged::<DraggedItem>(cx.window()){Action::Move(dragged_item.pane.clone(), dragged_item.handle.id())} else if let Some((_, project_entry)) =- drag_and_drop.currently_dragged::<ProjectEntryId>(cx.window_id())+ drag_and_drop.currently_dragged::<ProjectEntryId>(cx.window()){Action::Open(*project_entry)} else {