WIP

Antonio Scandurra created

Change summary

crates/auto_update/src/auto_update.rs           |  2 +-
crates/chat_panel/src/chat_panel.rs             |  2 +-
crates/contacts_panel/src/contacts_panel.rs     |  2 +-
crates/diagnostics/src/items.rs                 |  4 ++--
crates/editor/src/element.rs                    |  2 +-
crates/gpui/src/elements/mouse_event_handler.rs | 12 ++++++++----
crates/gpui/src/platform/event.rs               |  3 ++-
crates/gpui/src/platform/mac/event.rs           |  1 +
crates/gpui/src/views/select.rs                 |  4 ++--
crates/project_panel/src/project_panel.rs       | 14 ++++++++++----
crates/search/src/buffer_search.rs              |  4 ++--
crates/search/src/project_search.rs             |  4 ++--
crates/workspace/src/lsp_status.rs              |  2 +-
crates/workspace/src/pane.rs                    |  2 +-
crates/workspace/src/sidebar.rs                 |  2 +-
crates/workspace/src/workspace.rs               |  6 +++---
16 files changed, 39 insertions(+), 27 deletions(-)

Detailed changes

crates/auto_update/src/auto_update.rs 🔗

@@ -270,7 +270,7 @@ impl View for AutoUpdateIndicator {
                         )
                         .boxed()
                     })
-                    .on_click(|cx| cx.dispatch_action(DismissErrorMessage))
+                    .on_click(|_, cx| cx.dispatch_action(DismissErrorMessage))
                     .boxed()
                 }
                 AutoUpdateStatus::Idle => Empty::new().boxed(),

crates/chat_panel/src/chat_panel.rs 🔗

@@ -320,7 +320,7 @@ impl ChatPanel {
                 .boxed()
             })
             .with_cursor_style(CursorStyle::PointingHand)
-            .on_click(move |cx| {
+            .on_click(move |_, cx| {
                 let rpc = rpc.clone();
                 let this = this.clone();
                 cx.spawn(|mut cx| async move {

crates/contacts_panel/src/contacts_panel.rs 🔗

@@ -204,7 +204,7 @@ impl ContactsPanel {
                                 } else {
                                     CursorStyle::Arrow
                                 })
-                                .on_click(move |cx| {
+                                .on_click(move |_, cx| {
                                     if !is_host && !is_guest {
                                         cx.dispatch_global_action(JoinProject {
                                             project_id,

crates/diagnostics/src/items.rs 🔗

@@ -161,7 +161,7 @@ impl View for DiagnosticIndicator {
                     .boxed()
             })
             .with_cursor_style(CursorStyle::PointingHand)
-            .on_click(|cx| cx.dispatch_action(crate::Deploy))
+            .on_click(|_, cx| cx.dispatch_action(crate::Deploy))
             .aligned()
             .boxed(),
         );
@@ -194,7 +194,7 @@ impl View for DiagnosticIndicator {
                     .boxed()
                 })
                 .with_cursor_style(CursorStyle::PointingHand)
-                .on_click(|cx| cx.dispatch_action(GoToNextDiagnostic))
+                .on_click(|_, cx| cx.dispatch_action(GoToNextDiagnostic))
                 .boxed(),
             );
         }

crates/editor/src/element.rs 🔗

@@ -1189,7 +1189,7 @@ impl Element for EditorElement {
                 click_count,
                 ..
             } => self.mouse_down(*position, *alt, *shift, *click_count, layout, paint, cx),
-            Event::LeftMouseUp { position } => self.mouse_up(*position, cx),
+            Event::LeftMouseUp { position, .. } => self.mouse_up(*position, cx),
             Event::LeftMouseDragged { position } => {
                 self.mouse_dragged(*position, layout, paint, cx)
             }

crates/gpui/src/elements/mouse_event_handler.rs 🔗

@@ -15,7 +15,7 @@ pub struct MouseEventHandler {
     child: ElementBox,
     cursor_style: Option<CursorStyle>,
     mouse_down_handler: Option<Box<dyn FnMut(&mut EventContext)>>,
-    click_handler: Option<Box<dyn FnMut(&mut EventContext)>>,
+    click_handler: Option<Box<dyn FnMut(usize, &mut EventContext)>>,
     drag_handler: Option<Box<dyn FnMut(Vector2F, &mut EventContext)>>,
     padding: Padding,
 }
@@ -57,7 +57,7 @@ impl MouseEventHandler {
         self
     }
 
-    pub fn on_click(mut self, handler: impl FnMut(&mut EventContext) + 'static) -> Self {
+    pub fn on_click(mut self, handler: impl FnMut(usize, &mut EventContext) + 'static) -> Self {
         self.click_handler = Some(Box::new(handler));
         self
     }
@@ -151,14 +151,18 @@ impl Element for MouseEventHandler {
                     handled_in_child
                 }
             }
-            Event::LeftMouseUp { position, .. } => {
+            Event::LeftMouseUp {
+                position,
+                click_count,
+                ..
+            } => {
                 state.prev_drag_position = None;
                 if !handled_in_child && state.clicked {
                     state.clicked = false;
                     cx.notify();
                     if let Some(handler) = click_handler {
                         if hit_bounds.contains_point(*position) {
-                            handler(cx);
+                            handler(*click_count, cx);
                         }
                     }
                     true

crates/gpui/src/platform/event.rs 🔗

@@ -28,6 +28,7 @@ pub enum Event {
     },
     LeftMouseUp {
         position: Vector2F,
+        click_count: usize,
     },
     LeftMouseDragged {
         position: Vector2F,
@@ -68,7 +69,7 @@ impl Event {
             Event::KeyDown { .. } => None,
             Event::ScrollWheel { position, .. }
             | Event::LeftMouseDown { position, .. }
-            | Event::LeftMouseUp { position }
+            | Event::LeftMouseUp { position, .. }
             | Event::LeftMouseDragged { position }
             | Event::RightMouseDown { position, .. }
             | Event::RightMouseUp { position }

crates/gpui/src/platform/mac/event.rs 🔗

@@ -129,6 +129,7 @@ impl Event {
                     native_event.locationInWindow().x as f32,
                     window_height - native_event.locationInWindow().y as f32,
                 ),
+                click_count: native_event.clickCount() as usize,
             }),
             NSEventType::NSRightMouseDown => {
                 let modifiers = native_event.modifierFlags();

crates/gpui/src/views/select.rs 🔗

@@ -119,7 +119,7 @@ impl View for Select {
                 .with_style(style.header)
                 .boxed()
             })
-            .on_click(move |cx| cx.dispatch_action(ToggleSelect))
+            .on_click(move |_, cx| cx.dispatch_action(ToggleSelect))
             .boxed(),
         );
         if self.is_open {
@@ -153,7 +153,7 @@ impl View for Select {
                                                 )
                                             },
                                         )
-                                        .on_click(move |cx| cx.dispatch_action(SelectItem(ix)))
+                                        .on_click(move |_, cx| cx.dispatch_action(SelectItem(ix)))
                                         .boxed()
                                     }))
                                 },

crates/project_panel/src/project_panel.rs 🔗

@@ -69,7 +69,10 @@ struct EntryDetails {
 pub struct ToggleExpanded(pub ProjectEntryId);
 
 #[derive(Clone)]
-pub struct Open(pub ProjectEntryId);
+pub struct Open {
+    pub entry_id: ProjectEntryId,
+    pub change_focus: bool,
+}
 
 actions!(
     project_panel,
@@ -339,7 +342,7 @@ impl ProjectPanel {
     }
 
     fn open_entry(&mut self, action: &Open, cx: &mut ViewContext<Self>) {
-        cx.emit(Event::OpenedEntry(action.0));
+        cx.emit(Event::OpenedEntry(action.entry_id));
     }
 
     fn add_file(&mut self, _: &AddFile, cx: &mut ViewContext<Self>) {
@@ -799,11 +802,14 @@ impl ProjectPanel {
                 .with_padding_left(padding)
                 .boxed()
         })
-        .on_click(move |cx| {
+        .on_click(move |click_count, cx| {
             if kind == EntryKind::Dir {
                 cx.dispatch_action(ToggleExpanded(entry_id))
             } else {
-                cx.dispatch_action(Open(entry_id))
+                cx.dispatch_action(Open {
+                    entry_id,
+                    change_focus: click_count > 1,
+                })
             }
         })
         .with_cursor_style(CursorStyle::PointingHand)

crates/search/src/buffer_search.rs 🔗

@@ -292,7 +292,7 @@ impl BufferSearchBar {
                 .with_style(style.container)
                 .boxed()
         })
-        .on_click(move |cx| cx.dispatch_action(ToggleSearchOption(search_option)))
+        .on_click(move |_, cx| cx.dispatch_action(ToggleSearchOption(search_option)))
         .with_cursor_style(CursorStyle::PointingHand)
         .boxed()
     }
@@ -316,7 +316,7 @@ impl BufferSearchBar {
                 .with_style(style.container)
                 .boxed()
         })
-        .on_click(move |cx| match direction {
+        .on_click(move |_, cx| match direction {
             Direction::Prev => cx.dispatch_action(SelectPrevMatch),
             Direction::Next => cx.dispatch_action(SelectNextMatch),
         })

crates/search/src/project_search.rs 🔗

@@ -666,7 +666,7 @@ impl ProjectSearchBar {
                 .with_style(style.container)
                 .boxed()
         })
-        .on_click(move |cx| match direction {
+        .on_click(move |_, cx| match direction {
             Direction::Prev => cx.dispatch_action(SelectPrevMatch),
             Direction::Next => cx.dispatch_action(SelectNextMatch),
         })
@@ -693,7 +693,7 @@ impl ProjectSearchBar {
                 .with_style(style.container)
                 .boxed()
         })
-        .on_click(move |cx| cx.dispatch_action(ToggleSearchOption(option)))
+        .on_click(move |_, cx| cx.dispatch_action(ToggleSearchOption(option)))
         .with_cursor_style(CursorStyle::PointingHand)
         .boxed()
     }

crates/workspace/src/lsp_status.rs 🔗

@@ -168,7 +168,7 @@ impl View for LspStatus {
                     self.failed.join(", "),
                     if self.failed.len() > 1 { "s" } else { "" }
                 );
-                handler = Some(|cx: &mut EventContext| cx.dispatch_action(DismissErrorMessage));
+                handler = Some(|_, cx: &mut EventContext| cx.dispatch_action(DismissErrorMessage));
             } else {
                 return Empty::new().boxed();
             }

crates/workspace/src/pane.rs 🔗

@@ -737,7 +737,7 @@ impl Pane {
                                             .with_cursor_style(CursorStyle::PointingHand)
                                             .on_click({
                                                 let pane = pane.clone();
-                                                move |cx| {
+                                                move |_, cx| {
                                                     cx.dispatch_action(CloseItem {
                                                         item_id,
                                                         pane: pane.clone(),

crates/workspace/src/sidebar.rs 🔗

@@ -203,7 +203,7 @@ impl View for SidebarButtons {
                         .boxed()
                 })
                 .with_cursor_style(CursorStyle::PointingHand)
-                .on_click(move |cx| {
+                .on_click(move |_, cx| {
                     cx.dispatch_action(ToggleSidebarItem {
                         side,
                         item_index: ix,

crates/workspace/src/workspace.rs 🔗

@@ -1584,7 +1584,7 @@ impl Workspace {
                         .with_style(style.container)
                         .boxed()
                 })
-                .on_click(|cx| cx.dispatch_action(Authenticate))
+                .on_click(|_, cx| cx.dispatch_action(Authenticate))
                 .with_cursor_style(CursorStyle::PointingHand)
                 .aligned()
                 .boxed(),
@@ -1635,7 +1635,7 @@ impl Workspace {
         if let Some(peer_id) = peer_id {
             MouseEventHandler::new::<ToggleFollow, _, _>(replica_id.into(), cx, move |_, _| content)
                 .with_cursor_style(CursorStyle::PointingHand)
-                .on_click(move |cx| cx.dispatch_action(ToggleFollow(peer_id)))
+                .on_click(move |_, cx| cx.dispatch_action(ToggleFollow(peer_id)))
                 .boxed()
         } else {
             content
@@ -1667,7 +1667,7 @@ impl Workspace {
                         .boxed()
                 })
                 .with_cursor_style(CursorStyle::PointingHand)
-                .on_click(|cx| cx.dispatch_action(ToggleShare))
+                .on_click(|_, cx| cx.dispatch_action(ToggleShare))
                 .boxed(),
             )
         } else {