diff --git a/assets/keymaps/default-linux.json b/assets/keymaps/default-linux.json index f15c4dfe22b6c..cfde62803a6e8 100644 --- a/assets/keymaps/default-linux.json +++ b/assets/keymaps/default-linux.json @@ -107,7 +107,8 @@ "ctrl-'": "editor::ToggleHunkDiff", "ctrl-\"": "editor::ExpandAllHunkDiffs", "ctrl-i": "editor::ShowSignatureHelp", - "alt-g b": "editor::ToggleGitBlame" + "alt-g b": "editor::ToggleGitBlame", + "menu": "editor::OpenContextMenu" } }, { diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rs index 93c83af1950ec..a0b85b396c56c 100644 --- a/crates/editor/src/actions.rs +++ b/crates/editor/src/actions.rs @@ -271,6 +271,7 @@ gpui::actions!( NewlineBelow, NextInlineCompletion, NextScreen, + OpenContextMenu, OpenExcerpts, OpenExcerptsSplit, OpenFile, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index f797f82832f0a..f83a515c2c245 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -7107,6 +7107,16 @@ impl Editor { .update(cx, |buffer, cx| buffer.group_until_transaction(tx_id, cx)); } + pub fn open_context_menu(&mut self, _: &OpenContextMenu, cx: &mut ViewContext) { + self.request_autoscroll(Autoscroll::newest(), cx); + let position = self.selections.newest_display(cx).start; + // FIXME: scroll hasn't happened yet, so this is wrong in that case. + // Also seems errorprone to not use position in computing the point. + if let Some(point) = self.pixel_position_of_newest_cursor { + mouse_context_menu::deploy_context_menu(self, point, position, cx); + } + } + pub fn move_left(&mut self, _: &MoveLeft, cx: &mut ViewContext) { self.change_selections(Some(Autoscroll::fit()), cx, |s| { let line_mode = s.line_mode; diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 47107b9754687..b4622e7941191 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -170,6 +170,7 @@ impl EditorElement { crate::rust_analyzer_ext::apply_related_actions(view, cx); crate::clangd_ext::apply_related_actions(view, cx); + register_action(view, cx, Editor::open_context_menu); register_action(view, cx, Editor::move_left); register_action(view, cx, Editor::move_right); register_action(view, cx, Editor::move_down);