Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11586,15 +11586,12 @@ impl EditorSnapshot {
let renderer = cx.global::<GlobalBlameRenderer>().0.clone();
const MAX_RELATIVE_TIMESTAMP: &str = "2 years, 11 months ago";

/// The number of characters to dedicate to gaps and margins.
const SPACING_WIDTH: usize = 4;

let max_char_count = max_author_length.min(renderer.max_author_length())
+ ::git::SHORT_SHA_LENGTH
+ MAX_RELATIVE_TIMESTAMP.len()
+ SPACING_WIDTH;
+ MAX_RELATIVE_TIMESTAMP.len();

ch_advance * max_char_count
+ renderer.blame_entry_non_text_width(window, cx)
});

let is_singleton = self.buffer_snapshot().is_singleton();
Expand Down
6 changes: 5 additions & 1 deletion crates/editor/src/git/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use git::{
commit::ParsedCommitMessage,
};
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, Hsla, ScrollHandle, SharedString,
AnyElement, App, AppContext as _, Context, Entity, Hsla, Pixels, ScrollHandle, SharedString,
Subscription, Task, TextStyle, WeakEntity, Window,
};
use itertools::Itertools;
Expand Down Expand Up @@ -87,6 +87,10 @@ pub struct GitBlame {
pub trait BlameRenderer {
fn max_author_length(&self) -> usize;

fn blame_entry_non_text_width(&self, _: &Window, _: &App) -> Pixels {
Pixels::ZERO
}

fn render_blame_entry(
&self,
_: &TextStyle,
Expand Down
19 changes: 18 additions & 1 deletion crates/git_ui/src/blame_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use editor::{BlameRenderer, Editor, hover_markdown_style};
use git::{blame::BlameEntry, commit::ParsedCommitMessage, repository::CommitSummary};
use gpui::{
ClipboardItem, Entity, Hsla, MouseButton, ScrollHandle, Subscription, TextStyle,
ClipboardItem, Entity, Hsla, MouseButton, Pixels, Rems, ScrollHandle, Subscription, TextStyle,
TextStyleRefinement, UnderlineStyle, WeakEntity, prelude::*,
};
use markdown::{Markdown, MarkdownElement};
Expand All @@ -20,6 +20,9 @@ use ui::{ContextMenu, CopyButton, Divider, prelude::*, tooltip_container};
use workspace::Workspace;

const GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED: usize = 20;
const GIT_BLAME_GUTTER_MARGIN: Rems = rems(0.5);
const GIT_BLAME_GUTTER_GAP: Rems = rems(0.5);
const GIT_BLAME_AVATAR_SIZE: Rems = rems(1.);

pub struct GitBlameRenderer;

Expand Down Expand Up @@ -126,6 +129,19 @@ impl BlameRenderer for GitBlameRenderer {
GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED
}

fn blame_entry_non_text_width(&self, window: &Window, cx: &App) -> Pixels {
let show_avatar = ProjectSettings::get_global(cx).git.blame.show_avatar;
let gap_count = if show_avatar { 3. } else { 2. };
let width = GIT_BLAME_GUTTER_MARGIN.to_pixels(window.rem_size())
+ GIT_BLAME_GUTTER_GAP.to_pixels(window.rem_size()) * gap_count;

if show_avatar {
width + CommitAvatar::rendered_size(GIT_BLAME_AVATAR_SIZE, window)
} else {
width
}
}

fn render_blame_entry(
&self,
style: &TextStyle,
Expand Down Expand Up @@ -160,6 +176,7 @@ impl BlameRenderer for GitBlameRenderer {
author_email,
details.as_ref().and_then(|it| it.remote.as_ref()),
)
.size(GIT_BLAME_AVATAR_SIZE)
.render(window, cx),
)
} else {
Expand Down
17 changes: 10 additions & 7 deletions crates/git_ui/src/commit_tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use git::blame::BlameEntry;
use git::repository::CommitSummary;
use git::{GitRemote, commit::ParsedCommitMessage};
use gpui::{
AbsoluteLength, App, Asset, Element, Entity, MouseButton, ParentElement, Render, ScrollHandle,
StatefulInteractiveElement, WeakEntity, prelude::*,
AbsoluteLength, App, Asset, Element, Entity, MouseButton, ParentElement, Pixels, Render,
ScrollHandle, StatefulInteractiveElement, WeakEntity, prelude::*,
};
use markdown::{Markdown, MarkdownElement};
use project::git_store::Repository;
Expand Down Expand Up @@ -71,6 +71,8 @@ pub(crate) fn commit_tag_chips(tag_names: &[SharedString]) -> Option<impl IntoEl
)
}

const COMMIT_AVATAR_BORDER_WIDTH: Pixels = px(1.);

pub struct CommitAvatar<'a> {
sha: &'a SharedString,
author_email: Option<SharedString>,
Expand Down Expand Up @@ -109,21 +111,22 @@ impl<'a> CommitAvatar<'a> {
self
}

pub fn rendered_size(size: impl Into<AbsoluteLength>, window: &Window) -> Pixels {
size.into().to_pixels(window.rem_size()) + COMMIT_AVATAR_BORDER_WIDTH * 2.
}

pub fn render(&'a self, window: &mut Window, cx: &mut App) -> AnyElement {
let border_color = cx.theme().colors().border_variant;
let border_width = px(1.);

match self.avatar(window, cx) {
None => {
let container_size = self
.size
.map(|s| s.to_pixels(window.rem_size()) + border_width * 2.);
let container_size = self.size.map(|size| Self::rendered_size(size, window));

h_flex()
.when_some(container_size, |this, size| this.size(size))
.justify_center()
.rounded_full()
.border(border_width)
.border(COMMIT_AVATAR_BORDER_WIDTH)
.border_color(border_color)
.bg(cx.theme().colors().element_disabled)
.child(
Expand Down
Loading