git blame: add "Open permalink" to right-click menu (#11734)

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)
This commit is contained in:
Thorsten Ball 2024-05-13 09:47:03 +02:00 committed by GitHub
parent 8dd26553a3
commit 91b9e4ee9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,
},
@ -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))
@ -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<'_>,
@ -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| {