History

Style filenames and paths in project diff buffer headers according to git status (#25653)

This substitutes for the icons that we previously kept in these headers. cc @iamnbutler Release Notes: - N/A

Cole Miller committed 1 year ago

Commit eeac1a91 parent e83ebd11 file · +45 −6Browse files

Unified · Split

crates/editor/src/element.rs+45−6
@@ -28,7 +28,7 @@ use buffer_diff::{DiffHunkSecondaryStatus, DiffHunkStatus, DiffHunkStatusKind}; · 27 unmodified lines
2828 use client::ParticipantIndex;
2929 use collections::{BTreeMap, HashMap, HashSet};
3030 use file_icons::FileIcons;
31−use git::{blame::BlameEntry, Oid};
31+use git::{blame::BlameEntry, status::FileStatus, Oid};
3232 use gpui::{
3333 anchored, deferred, div, fill, linear_color_stop, linear_gradient, outline, point, px, quad,
3434 relative, size, svg, transparent_black, Action, AnyElement, App, AvailableSpace, Axis, Bounds,
@@ -73,7 +73,7 @@ use ui::{ · 38 unmodified lines
7373 POPOVER_Y_PADDING,
7474 };
7575 use unicode_segmentation::UnicodeSegmentation;
76−use util::{debug_panic, RangeExt, ResultExt};
76+use util::{debug_panic, maybe, RangeExt, ResultExt};
7777 use workspace::{item::Item, notifications::NotifyTaskExt};
7878
7979 const INLINE_BLAME_PADDING_EM_WIDTHS: f32 = 7.;
@@ -2646,6 +2646,21 @@ impl EditorElement { · 2566 unmodified lines
26462646 window: &mut Window,
26472647 cx: &mut App,
26482648 ) -> Div {
2649+ let file_status = maybe!({
2650+ let project = self.editor.read(cx).project.as_ref()?.read(cx);
2651+ let (repo, path) =
2652+ project.repository_and_path_for_buffer_id(for_excerpt.buffer_id, cx)?;
2653+ let status = repo.read(cx).repository_entry.status_for_path(&path)?;
2654+ Some(status.status)
2655+ })
2656+ .filter(|_| {
2657+ self.editor
2658+ .read(cx)
2659+ .buffer
2660+ .read(cx)
2661+ .all_diff_hunks_expanded()
2662+ });
2663+
26492664 let include_root = self
26502665 .editor
26512666 .read(cx)
@@ -2749,12 +2764,36 @@ impl EditorElement { · 97 unmodified lines
27492764 h_flex()
27502765 .gap_2()
27512766 .child(
2752− filename
2753− .map(SharedString::from)
2754− .unwrap_or_else(|| "untitled".into()),
2767+ Label::new(
2768+ filename
2769+ .map(SharedString::from)
2770+ .unwrap_or_else(|| "untitled".into()),
2771+ )
2772+ .single_line()
2773+ .when_some(
2774+ file_status,
2775+ |el, status| {
2776+ el.color(if status.is_conflicted() {
2777+ Color::Conflict
2778+ } else if status.is_modified() {
2779+ Color::Modified
2780+ } else if status.is_deleted() {
2781+ Color::Disabled
2782+ } else {
2783+ Color::Created
2784+ })
2785+ .when(status.is_deleted(), |el| el.strikethrough())
2786+ },
2787+ ),
27552788 )
27562789 .when_some(parent_path, |then, path| {
2757− then.child(div().child(path).text_color(colors.text_muted))
2790+ then.child(div().child(path).text_color(
2791+ if file_status.is_some_and(FileStatus::is_deleted) {
2792+ colors.text_disabled
2793+ } else {
2794+ colors.text_muted
2795+ },
2796+ ))
27582797 }),
27592798 )
27602799 .when(is_selected, |el| {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t