Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Dismiss drag selection when dropped outside editor (#32382)
CharlesChen0823eb5f59577d63
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex b0710240d7c..5ff649222ea 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -918,6 +918,7 @@ enum SelectionDragState {Dragging {selection: Selection<Anchor>,drop_cursor: Selection<Anchor>,+ hide_drop_cursor: bool,},}diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 52101f35fd5..7c2f2c8845f 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -856,8 +856,11 @@ impl EditorElement {SelectionDragState::Dragging { ref selection, .. } => {let snapshot = editor.snapshot(window, cx);let selection_display = selection.map(|anchor| anchor.to_display_point(&snapshot));- if !point_for_position.intersects_selection(&selection_display) {- let is_cut = !event.modifiers.control;+ if !point_for_position.intersects_selection(&selection_display)+ && text_hitbox.is_hovered(window)+ {+ let is_cut = !(cfg!(target_os = "macos") && event.modifiers.alt+ || cfg!(not(target_os = "macos")) && event.modifiers.control);editor.move_selection_on_drop(&selection.clone(),point_for_position.previous_valid,@@ -865,10 +868,11 @@ impl EditorElement {window,cx,);- editor.selection_drag_state = SelectionDragState::None;- cx.stop_propagation();- return;}+ editor.selection_drag_state = SelectionDragState::None;+ cx.stop_propagation();+ cx.notify();+ return;}_ => {}}@@ -941,7 +945,8 @@ impl EditorElement {return;}- let text_bounds = position_map.text_hitbox.bounds;+ let text_hitbox = &position_map.text_hitbox;+ let text_bounds = text_hitbox.bounds;let point_for_position = position_map.point_for_position(event.position);let mut scroll_delta = gpui::Point::<f32>::default();@@ -982,10 +987,12 @@ impl EditorElement {match editor.selection_drag_state {SelectionDragState::Dragging {ref mut drop_cursor,+ ref mut hide_drop_cursor,..} => {drop_cursor.start = drop_anchor;drop_cursor.end = drop_anchor;+ *hide_drop_cursor = !text_hitbox.is_hovered(window);}SelectionDragState::ReadyToDrag { ref selection, .. } => {let drop_cursor = Selection {@@ -998,6 +1005,7 @@ impl EditorElement {editor.selection_drag_state = SelectionDragState::Dragging {selection: selection.clone(),drop_cursor,+ hide_drop_cursor: false,};}_ => {}@@ -1251,16 +1259,18 @@ impl EditorElement {if let SelectionDragState::Dragging {ref selection,ref drop_cursor,+ ref hide_drop_cursor,} = editor.selection_drag_state{- if drop_cursor- .start- .cmp(&selection.start, &snapshot.buffer_snapshot)- .eq(&Ordering::Less)- || drop_cursor- .end- .cmp(&selection.end, &snapshot.buffer_snapshot)- .eq(&Ordering::Greater)+ if !hide_drop_cursor+ && (drop_cursor+ .start+ .cmp(&selection.start, &snapshot.buffer_snapshot)+ .eq(&Ordering::Less)+ || drop_cursor+ .end+ .cmp(&selection.end, &snapshot.buffer_snapshot)+ .eq(&Ordering::Greater)){let drag_cursor_layout = SelectionLayout::new(drop_cursor.clone(),