Skip to content

Commit 1e45c99

Browse files
authored
Improve readability of files in the git changes panel (zed-industries#41857)
Closes _unknown_ <img width="1212" height="463" alt="image" src="https://github.com/user-attachments/assets/ec00fcf0-7eb9-4291-b1e2-66e014dc30ac" /> This PR places the file_name before the file_path so that when the panel is slim it is still usable, mirrors the behaviour of the file picker (cmd+P) Release Notes: - Improved readability of files in the git changes panel
1 parent 28f5097 commit 1e45c99

File tree

6 files changed

+127
-20
lines changed

6 files changed

+127
-20
lines changed

assets/settings/default.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,10 @@
13161316
// "hunk_style": "staged_hollow"
13171317
// 2. Show unstaged hunks hollow and staged hunks filled:
13181318
// "hunk_style": "unstaged_hollow"
1319-
"hunk_style": "staged_hollow"
1319+
"hunk_style": "staged_hollow",
1320+
// Should the name or path be displayed first in the git view.
1321+
// "path_style": "file_name_first" or "file_path_first"
1322+
"path_style": "file_name_first"
13201323
},
13211324
// The list of custom Git hosting providers.
13221325
"git_hosting_providers": [

crates/git_ui/src/git_panel.rs

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use panel::{
5151
use project::{
5252
Fs, Project, ProjectPath,
5353
git_store::{GitStoreEvent, Repository, RepositoryEvent, RepositoryId, pending_op},
54+
project_settings::{GitPathStyle, ProjectSettings},
5455
};
5556
use serde::{Deserialize, Serialize};
5657
use settings::{Settings, SettingsStore, StatusStyle};
@@ -3954,6 +3955,7 @@ impl GitPanel {
39543955
cx: &Context<Self>,
39553956
) -> AnyElement {
39563957
let path_style = self.project.read(cx).path_style(cx);
3958+
let git_path_style = ProjectSettings::get_global(cx).git.path_style;
39573959
let display_name = entry.display_name(path_style);
39583960

39593961
let selected = self.selected_entry == Some(ix);
@@ -4053,7 +4055,6 @@ impl GitPanel {
40534055
} else {
40544056
cx.theme().colors().ghost_element_active
40554057
};
4056-
40574058
h_flex()
40584059
.id(id)
40594060
.h(self.list_item_height())
@@ -4151,28 +4152,70 @@ impl GitPanel {
41514152
h_flex()
41524153
.items_center()
41534154
.flex_1()
4154-
// .overflow_hidden()
4155-
.when_some(entry.parent_dir(path_style), |this, parent| {
4156-
if !parent.is_empty() {
4157-
this.child(
4158-
self.entry_label(
4159-
format!("{parent}{}", path_style.separator()),
4160-
path_color,
4161-
)
4162-
.when(status.is_deleted(), |this| this.strikethrough()),
4163-
)
4164-
} else {
4165-
this
4166-
}
4167-
})
4168-
.child(
4169-
self.entry_label(display_name, label_color)
4170-
.when(status.is_deleted(), |this| this.strikethrough()),
4171-
),
4155+
.child(h_flex().items_center().flex_1().map(|this| {
4156+
self.path_formatted(
4157+
this,
4158+
entry.parent_dir(path_style),
4159+
path_color,
4160+
display_name,
4161+
label_color,
4162+
path_style,
4163+
git_path_style,
4164+
status.is_deleted(),
4165+
)
4166+
})),
41724167
)
41734168
.into_any_element()
41744169
}
41754170

4171+
fn path_formatted(
4172+
&self,
4173+
parent: Div,
4174+
directory: Option<String>,
4175+
path_color: Color,
4176+
file_name: String,
4177+
label_color: Color,
4178+
path_style: PathStyle,
4179+
git_path_style: GitPathStyle,
4180+
strikethrough: bool,
4181+
) -> Div {
4182+
parent
4183+
.when(git_path_style == GitPathStyle::FileNameFirst, |this| {
4184+
this.child(
4185+
self.entry_label(
4186+
match directory.as_ref().is_none_or(|d| d.is_empty()) {
4187+
true => file_name.clone(),
4188+
false => format!("{file_name} "),
4189+
},
4190+
label_color,
4191+
)
4192+
.when(strikethrough, Label::strikethrough),
4193+
)
4194+
})
4195+
.when_some(directory, |this, dir| {
4196+
match (
4197+
!dir.is_empty(),
4198+
git_path_style == GitPathStyle::FileNameFirst,
4199+
) {
4200+
(true, true) => this.child(
4201+
self.entry_label(dir, path_color)
4202+
.when(strikethrough, Label::strikethrough),
4203+
),
4204+
(true, false) => this.child(
4205+
self.entry_label(format!("{dir}{}", path_style.separator()), path_color)
4206+
.when(strikethrough, Label::strikethrough),
4207+
),
4208+
_ => this,
4209+
}
4210+
})
4211+
.when(git_path_style == GitPathStyle::FilePathFirst, |this| {
4212+
this.child(
4213+
self.entry_label(file_name, label_color)
4214+
.when(strikethrough, Label::strikethrough),
4215+
)
4216+
})
4217+
}
4218+
41764219
fn has_write_access(&self, cx: &App) -> bool {
41774220
!self.project.read(cx).is_read_only(cx)
41784221
}

crates/project/src/project_settings.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,26 @@ pub struct GitSettings {
348348
///
349349
/// Default: staged_hollow
350350
pub hunk_style: settings::GitHunkStyleSetting,
351+
/// How file paths are displayed in the git gutter.
352+
///
353+
/// Default: file_name_first
354+
pub path_style: GitPathStyle,
355+
}
356+
357+
#[derive(Clone, Copy, Debug, PartialEq, Default)]
358+
pub enum GitPathStyle {
359+
#[default]
360+
FileNameFirst,
361+
FilePathFirst,
362+
}
363+
364+
impl From<settings::GitPathStyle> for GitPathStyle {
365+
fn from(style: settings::GitPathStyle) -> Self {
366+
match style {
367+
settings::GitPathStyle::FileNameFirst => GitPathStyle::FileNameFirst,
368+
settings::GitPathStyle::FilePathFirst => GitPathStyle::FilePathFirst,
369+
}
370+
}
351371
}
352372

353373
#[derive(Clone, Copy, Debug)]
@@ -501,6 +521,7 @@ impl Settings for ProjectSettings {
501521
}
502522
},
503523
hunk_style: git.hunk_style.unwrap(),
524+
path_style: git.path_style.unwrap().into(),
504525
};
505526
Self {
506527
context_servers: project

crates/settings/src/settings_content/project.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ pub struct GitSettings {
311311
///
312312
/// Default: staged_hollow
313313
pub hunk_style: Option<GitHunkStyleSetting>,
314+
/// How file paths are displayed in the git gutter.
315+
///
316+
/// Default: file_name_first
317+
pub path_style: Option<GitPathStyle>,
314318
}
315319

316320
#[derive(
@@ -406,6 +410,28 @@ pub enum GitHunkStyleSetting {
406410
UnstagedHollow,
407411
}
408412

413+
#[derive(
414+
Copy,
415+
Clone,
416+
Debug,
417+
PartialEq,
418+
Default,
419+
Serialize,
420+
Deserialize,
421+
JsonSchema,
422+
MergeFrom,
423+
strum::VariantArray,
424+
strum::VariantNames,
425+
)]
426+
#[serde(rename_all = "snake_case")]
427+
pub enum GitPathStyle {
428+
/// Show file name first, then path
429+
#[default]
430+
FileNameFirst,
431+
/// Show full path first
432+
FilePathFirst,
433+
}
434+
409435
#[skip_serializing_none]
410436
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
411437
pub struct DiagnosticsSettingsContent {

crates/settings_ui/src/page_data.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5494,6 +5494,19 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
54945494
metadata: None,
54955495
files: USER,
54965496
}),
5497+
SettingsPageItem::SettingItem(SettingItem {
5498+
title: "Path Style",
5499+
description: "Should the name or path be displayed first in the git view.",
5500+
field: Box::new(SettingField {
5501+
json_path: Some("git.path_style"),
5502+
pick: |settings_content| settings_content.git.as_ref()?.path_style.as_ref(),
5503+
write: |settings_content, value| {
5504+
settings_content.git.get_or_insert_default().path_style = value;
5505+
},
5506+
}),
5507+
metadata: None,
5508+
files: USER,
5509+
}),
54975510
],
54985511
},
54995512
SettingsPage {

crates/settings_ui/src/settings_ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ fn init_renderers(cx: &mut App) {
452452
.add_basic_renderer::<settings::DockPosition>(render_dropdown)
453453
.add_basic_renderer::<settings::GitGutterSetting>(render_dropdown)
454454
.add_basic_renderer::<settings::GitHunkStyleSetting>(render_dropdown)
455+
.add_basic_renderer::<settings::GitPathStyle>(render_dropdown)
455456
.add_basic_renderer::<settings::DiagnosticSeverityContent>(render_dropdown)
456457
.add_basic_renderer::<settings::SeedQuerySetting>(render_dropdown)
457458
.add_basic_renderer::<settings::DoubleClickInMultibuffer>(render_dropdown)

0 commit comments

Comments
 (0)