From 3409ee1785333d8a947613bd3c0d0e9aaa5181ed Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 28 Apr 2023 16:41:46 +0200 Subject: [PATCH] Remove `DeployMouseContextMenu` internal action Co-Authored-By: Nathan Sobo --- crates/editor/src/editor.rs | 1 - crates/editor/src/element.rs | 9 ++++--- crates/editor/src/mouse_context_menu.rs | 34 ++++--------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b76f79b807a3f2e167ce4c9cfe5d8eb2d9019a24..a37def67b1e343aa3f2512167c906023c46900f8 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -386,7 +386,6 @@ pub fn init(cx: &mut AppContext) { cx.add_action(Editor::copilot_suggest); hover_popover::init(cx); - mouse_context_menu::init(cx); scroll::actions::init(cx); workspace::register_project_item::(cx); diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index bb209967fb16c0c82f50223693c447841992c944..e3a160175d63fcd991fbedc5639585377e209b97 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -13,7 +13,7 @@ use crate::{ link_go_to_definition::{ go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link, }, - mouse_context_menu::DeployMouseContextMenu, + mouse_context_menu, scroll::actions::Scroll, EditorStyle, GutterHover, UnfoldAt, }; @@ -131,8 +131,9 @@ impl EditorElement { }) .on_down(MouseButton::Right, { let position_map = position_map.clone(); - move |event, _editor, cx| { + move |event, editor, cx| { if !Self::mouse_right_down( + editor, event.position, position_map.as_ref(), text_bounds, @@ -278,6 +279,7 @@ impl EditorElement { } fn mouse_right_down( + editor: &mut Editor, position: Vector2F, position_map: &PositionMap, text_bounds: RectF, @@ -288,8 +290,7 @@ impl EditorElement { } let (point, _) = position_map.point_for_position(text_bounds, position); - - cx.dispatch_action(DeployMouseContextMenu { position, point }); + mouse_context_menu::deploy_context_menu(editor, position, point, cx); true } diff --git a/crates/editor/src/mouse_context_menu.rs b/crates/editor/src/mouse_context_menu.rs index f30bb3159aaccebfedd116263d85adfffe168c2d..b892fffbcac3cd0a1e76966a5a8190a89fcf8d2a 100644 --- a/crates/editor/src/mouse_context_menu.rs +++ b/crates/editor/src/mouse_context_menu.rs @@ -1,29 +1,14 @@ -use context_menu::ContextMenuItem; -use gpui::{ - elements::AnchorCorner, geometry::vector::Vector2F, impl_internal_actions, AppContext, - ViewContext, -}; - use crate::{ DisplayPoint, Editor, EditorMode, FindAllReferences, GoToDefinition, GoToTypeDefinition, Rename, RevealInFinder, SelectMode, ToggleCodeActions, }; - -#[derive(Clone, PartialEq)] -pub struct DeployMouseContextMenu { - pub position: Vector2F, - pub point: DisplayPoint, -} - -impl_internal_actions!(editor, [DeployMouseContextMenu]); - -pub fn init(cx: &mut AppContext) { - cx.add_action(deploy_context_menu); -} +use context_menu::ContextMenuItem; +use gpui::{elements::AnchorCorner, geometry::vector::Vector2F, ViewContext}; pub fn deploy_context_menu( editor: &mut Editor, - &DeployMouseContextMenu { position, point }: &DeployMouseContextMenu, + position: Vector2F, + point: DisplayPoint, cx: &mut ViewContext, ) { if !editor.focused { @@ -98,16 +83,7 @@ mod tests { do_wˇork(); } "}); - cx.update_editor(|editor, cx| { - deploy_context_menu( - editor, - &DeployMouseContextMenu { - position: Default::default(), - point, - }, - cx, - ) - }); + cx.update_editor(|editor, cx| deploy_context_menu(editor, Default::default(), point, cx)); cx.assert_editor_state(indoc! {" fn test() {