Compare commits

...

2 Commits

Author SHA1 Message Date
João Marcos
e18caef72a broken impl 2025-02-01 06:11:28 -03:00
João Marcos
6d5281faeb Fix inconsistent hash colors in git blame 2025-02-01 05:45:14 -03:00

View File

@@ -1754,19 +1754,39 @@ impl EditorElement {
let scroll_top = scroll_position.y * line_height;
let start_x = em_width;
let mut last_used_color: Option<(PlayerColor, Oid)> = None;
let mut previous_color_and_oid: Option<(Hsla, Oid)> = None;
let shaped_lines = blamed_rows
.into_iter()
.enumerate()
.flat_map(|(ix, blame_entry)| {
if let Some(blame_entry) = blame_entry {
let sha_color = {
let color_ix: u32 = blame_entry.sha.into();
let get_color =
|ix: u32| cx.theme().players().color_for_participant(ix).cursor;
let mut sha_color = get_color(color_ix);
if let Some((previous_color, previous_sha)) = previous_color_and_oid {
if blame_entry.sha != previous_sha {
if sha_color == previous_color {
// Don't give consecutive entries the same color, overwrite
sha_color = get_color(color_ix + 1);
}
} else {
sha_color = previous_color;
}
}
previous_color_and_oid = Some((sha_color, blame_entry.sha));
sha_color
};
let mut element = render_blame_entry(
ix,
&blame,
blame_entry,
&self.style,
&mut last_used_color,
sha_color,
self.editor.clone(),
cx,
);
@@ -5670,25 +5690,10 @@ fn render_blame_entry(
blame: &gpui::Entity<GitBlame>,
blame_entry: BlameEntry,
style: &EditorStyle,
last_used_color: &mut Option<(PlayerColor, Oid)>,
sha_color: Hsla,
editor: Entity<Editor>,
cx: &mut App,
) -> AnyElement {
let mut sha_color = cx
.theme()
.players()
.color_for_participant(blame_entry.sha.into());
// If the last color we used is the same as the one we get for this line, but
// the commit SHAs are different, then we try again to get a different color.
match *last_used_color {
Some((color, sha)) if sha != blame_entry.sha && color.cursor == sha_color.cursor => {
let index: u32 = blame_entry.sha.into();
sha_color = cx.theme().players().color_for_participant(index + 1);
}
_ => {}
};
last_used_color.replace((sha_color, blame_entry.sha));
let relative_timestamp = blame_entry_relative_timestamp(&blame_entry);
let short_commit_id = blame_entry.sha.display_short();
@@ -5716,7 +5721,7 @@ fn render_blame_entry(
h_flex()
.items_center()
.gap_2()
.child(div().text_color(sha_color.cursor).child(short_commit_id))
.child(div().text_color(sha_color).child(short_commit_id))
.child(name),
)
.child(relative_timestamp)