Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Remove `DeployMouseContextMenu` internal action

Antonio Scandurra3409ee178533
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index b76f79b807a..a37def67b1e 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::<Editor>(cx);
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index bb209967fb1..e3a160175d6 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 f30bb3159aa..b892fffbcac 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<Editor>,
) {
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() {