git_ui: Render avatars in git blame gutter (#39168)
Release Notes: - Added setting to render avatar in blame gutter
This commit is contained in:
@@ -28,25 +28,33 @@ pub struct CommitDetails {
|
||||
}
|
||||
|
||||
pub struct CommitAvatar<'a> {
|
||||
commit: &'a CommitDetails,
|
||||
sha: &'a SharedString,
|
||||
remote: Option<&'a GitRemote>,
|
||||
}
|
||||
|
||||
impl<'a> CommitAvatar<'a> {
|
||||
pub fn new(details: &'a CommitDetails) -> Self {
|
||||
Self { commit: details }
|
||||
pub fn new(sha: &'a SharedString, remote: Option<&'a GitRemote>) -> Self {
|
||||
Self { sha, remote }
|
||||
}
|
||||
|
||||
pub fn from_commit_details(details: &'a CommitDetails) -> Self {
|
||||
Self {
|
||||
sha: &details.sha,
|
||||
remote: details
|
||||
.message
|
||||
.as_ref()
|
||||
.and_then(|details| details.remote.as_ref()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> CommitAvatar<'a> {
|
||||
pub fn render(&'a self, window: &mut Window, cx: &mut App) -> Option<impl IntoElement + use<>> {
|
||||
let remote = self
|
||||
.commit
|
||||
.message
|
||||
.as_ref()
|
||||
.and_then(|details| details.remote.clone())
|
||||
.remote
|
||||
.filter(|remote| remote.host_supports_avatars())?;
|
||||
|
||||
let avatar_url = CommitAvatarAsset::new(remote, self.commit.sha.clone());
|
||||
let avatar_url = CommitAvatarAsset::new(remote.clone(), self.sha.clone());
|
||||
|
||||
let element = match window.use_asset::<CommitAvatarAsset>(&avatar_url, cx) {
|
||||
// Loading or no avatar found
|
||||
@@ -169,7 +177,7 @@ impl CommitTooltip {
|
||||
|
||||
impl Render for CommitTooltip {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let avatar = CommitAvatar::new(&self.commit).render(window, cx);
|
||||
let avatar = CommitAvatar::from_commit_details(&self.commit).render(window, cx);
|
||||
|
||||
let author = self.commit.author_name.clone();
|
||||
|
||||
@@ -233,7 +241,7 @@ impl Render for CommitTooltip {
|
||||
has_parent: false,
|
||||
};
|
||||
|
||||
tooltip_container(window, cx, move |this, _, cx| {
|
||||
tooltip_container(cx, move |this, cx| {
|
||||
this.occlude()
|
||||
.on_mouse_move(|_, _, cx| cx.stop_propagation())
|
||||
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
|
||||
|
||||
Reference in New Issue
Block a user