Skip to content

Commit

Permalink
Add action for opening context menu at cursor (zed-industries#17819)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Sep 24, 2024
1 parent 8103ac1 commit d432bcc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion assets/keymaps/default-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
1 change: 1 addition & 0 deletions crates/editor/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ gpui::actions!(
NewlineBelow,
NextInlineCompletion,
NextScreen,
OpenContextMenu,
OpenExcerpts,
OpenExcerptsSplit,
OpenFile,
Expand Down
10 changes: 10 additions & 0 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
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>) {
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
let line_mode = s.line_mode;
Expand Down
1 change: 1 addition & 0 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d432bcc

Please sign in to comment.