From 0c4f798a2d3278b81a7dbd8e60eaded22c73eeae Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Tue, 31 May 2022 10:17:29 -0700 Subject: [PATCH] WIP jump to definition with mouse --- crates/editor/src/editor.rs | 9 +++++++-- crates/editor/src/element.rs | 21 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index db287fe65af736f0ed46a5c071fe0b1a75a2efc7..00201dbd3208fcdc44925931ed3f940045dac13d 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -113,6 +113,11 @@ pub struct ConfirmCodeAction { pub item_ix: Option, } +#[derive(Clone, Default)] +pub struct GoToDefinitionAt { + pub location: Option, +} + actions!( editor, [ @@ -173,10 +178,10 @@ actions!( ToggleComments, SelectLargerSyntaxNode, SelectSmallerSyntaxNode, + GoToDefinition, MoveToEnclosingBracket, UndoSelection, RedoSelection, - GoToDefinition, FindAllReferences, Rename, ConfirmRename, @@ -204,7 +209,7 @@ impl_actions!( ] ); -impl_internal_actions!(editor, [Scroll, Select]); +impl_internal_actions!(editor, [Scroll, Select, GoToDefinitionAt]); enum DocumentHighlightRead {} enum DocumentHighlightWrite {} diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 771bc1049c5131db9d9e7c59386693685f46f864..daeb9b56948f65e5e230345d82248bbd83381403 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -5,7 +5,7 @@ use super::{ }; use crate::{ display_map::{DisplaySnapshot, TransformBlock}, - EditorStyle, + EditorStyle, GoToDefinition, }; use clock::ReplicaId; use collections::{BTreeMap, HashMap}; @@ -102,6 +102,7 @@ impl EditorElement { fn mouse_down( &self, position: Vector2F, + cmd: bool, alt: bool, shift: bool, mut click_count: usize, @@ -118,7 +119,11 @@ impl EditorElement { let snapshot = self.snapshot(cx.app); let (position, overshoot) = paint.point_for_position(&snapshot, layout, position); - if shift && alt { + if cmd { + cx.dispatch_action(GoToDefinitionAt { + location: Some(position), + }); + } else if shift && alt { cx.dispatch_action(Select(SelectPhase::BeginColumnar { position, overshoot, @@ -1222,11 +1227,21 @@ impl Element for EditorElement { match event { Event::LeftMouseDown { position, + cmd, alt, shift, click_count, .. - } => self.mouse_down(*position, *alt, *shift, *click_count, layout, paint, cx), + } => self.mouse_down( + *position, + *cmd, + *alt, + *shift, + *click_count, + layout, + paint, + cx, + ), Event::LeftMouseUp { position, .. } => self.mouse_up(*position, cx), Event::LeftMouseDragged { position } => { self.mouse_dragged(*position, layout, paint, cx)