Skip to content

Commit

Permalink
git blame: add "Open permalink" to right-click menu (#11734)
Browse files Browse the repository at this point in the history
This adds a new option to the right click menu for git blame entries in
the gutter: "Open permalink". If there is a URL for the code host, then
this will open it.

Release Notes:

- Added "Open permalink" option to right-click menu of git blame entries
in gutter.

Demo:

![screenshot-2024-05-13-09 39
48@2x](https://github.com/zed-industries/zed/assets/1185253/656c177c-79f0-4a40-8838-7e963d099479)
  • Loading branch information
mrnugget authored May 13, 2024
1 parent 8dd2655 commit 91b9e4e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use crate::{
TransformBlock,
},
editor_settings::{DoubleClickInMultibuffer, MultiCursorModifier, ShowScrollbar},
git::{blame::GitBlame, diff_hunk_to_display, DisplayDiffHunk},
git::{
blame::{CommitDetails, GitBlame},
diff_hunk_to_display, DisplayDiffHunk,
},
hover_popover::{
self, hover_at, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH, MIN_POPOVER_LINE_HEIGHT,
},
Expand Down Expand Up @@ -3431,8 +3434,15 @@ fn render_blame_entry(
])
.on_mouse_down(MouseButton::Right, {
let blame_entry = blame_entry.clone();
let details = details.clone();
move |event, cx| {
deploy_blame_entry_context_menu(&blame_entry, editor.clone(), event.position, cx);
deploy_blame_entry_context_menu(
&blame_entry,
details.as_ref(),
editor.clone(),
event.position,
cx,
);
}
})
.hover(|style| style.bg(cx.theme().colors().element_hover))
Expand All @@ -3452,6 +3462,7 @@ fn render_blame_entry(

fn deploy_blame_entry_context_menu(
blame_entry: &BlameEntry,
details: Option<&CommitDetails>,
editor: View<Editor>,
position: gpui::Point<Pixels>,
cx: &mut WindowContext<'_>,
Expand All @@ -3461,6 +3472,10 @@ fn deploy_blame_entry_context_menu(
this.entry("Copy commit SHA", None, move |cx| {
cx.write_to_clipboard(ClipboardItem::new(sha.clone()));
})
.when_some(
details.and_then(|details| details.permalink.clone()),
|this, url| this.entry("Open permalink", None, move |cx| cx.open_url(url.as_str())),
)
});

editor.update(cx, move |editor, cx| {
Expand Down

0 comments on commit 91b9e4e

Please sign in to comment.