Skip to content

Commit

Permalink
Project panel worktree entry spacing configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesun committed Aug 14, 2024
1 parent a5961c8 commit 2a9d755
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
2 changes: 2 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@
"default_width": 240,
// Where to dock the project panel. Can be 'left' or 'right'.
"dock": "left",
// Spacing between worktree entries in the project panel.
"entry_spacing": "comfortable",
// Whether to show file icons in the project panel.
"file_icons": true,
// Whether to show folder icons or chevrons for directories in the project panel.
Expand Down
10 changes: 9 additions & 1 deletion crates/project_panel/src/project_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ use std::{
time::Duration,
};
use theme::ThemeSettings;
use ui::{prelude::*, v_flex, ContextMenu, Icon, KeyBinding, Label, ListItem, Tooltip};
use ui::{
prelude::*, v_flex, ContextMenu, Icon, KeyBinding, Label, ListItem, ListItemSpacing, Tooltip,
};
use util::{maybe, ResultExt, TryFutureExt};
use workspace::{
dock::{DockPosition, Panel, PanelEvent},
Expand Down Expand Up @@ -2103,6 +2105,12 @@ impl ProjectPanel {
ListItem::new(entry_id.to_proto() as usize)
.indent_level(depth)
.indent_step_size(px(settings.indent_size))
.spacing(match settings.entry_spacing {
project_panel_settings::EntrySpacing::Comfortable => ListItemSpacing::Dense,
project_panel_settings::EntrySpacing::Compact => {
ListItemSpacing::ExtraDense
}
})
.selected(is_marked || is_active)
.when_some(canonical_path, |this, path| {
this.end_slot::<AnyElement>(
Expand Down
18 changes: 18 additions & 0 deletions crates/project_panel/src/project_panel_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct ProjectPanelSettings {
pub button: bool,
pub default_width: Pixels,
pub dock: ProjectPanelDockPosition,
pub entry_spacing: EntrySpacing,
pub file_icons: bool,
pub folder_icons: bool,
pub git_status: bool,
Expand All @@ -25,6 +26,19 @@ pub struct ProjectPanelSettings {
pub scrollbar: ScrollbarSettings,
}

/// Spacing between worktree entries in the project panel.
///
/// Default: comfortable
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum EntrySpacing {
#[default]
/// Comfortable spacing of entries.
Comfortable,
/// Compact spacing of entries.
Compact,
}

/// When to show the scrollbar in the project panel.
///
/// Default: always
Expand Down Expand Up @@ -68,6 +82,10 @@ pub struct ProjectPanelSettingsContent {
///
/// Default: left
pub dock: Option<ProjectPanelDockPosition>,
/// Spacing between worktree entries in the project panel.
///
/// Default: comfortable
pub entry_spacing: Option<EntrySpacing>,
/// Whether to show file icons in the project panel.
///
/// Default: true
Expand Down
2 changes: 2 additions & 0 deletions crates/ui/src/components/list/list_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum ListItemSpacing {
#[default]
Dense,
Sparse,
ExtraDense,
}

#[derive(IntoElement)]
Expand Down Expand Up @@ -189,6 +190,7 @@ impl RenderOnce for ListItem {
.map(|this| match self.spacing {
ListItemSpacing::Dense => this,
ListItemSpacing::Sparse => this.py_1(),
ListItemSpacing::ExtraDense => this.py_neg_px(),
})
.group("list_item")
.when(self.inset && !self.disabled, |this| {
Expand Down
25 changes: 25 additions & 0 deletions docs/src/configuring-zed.md
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,7 @@ Run the `theme selector: toggle` action in the command palette to see a current
"button": true,
"default_width": 240,
"dock": "left",
"entry_spacing": "comfortable",
"file_icons": true,
"folder_icons": true,
"git_status": true,
Expand Down Expand Up @@ -1611,6 +1612,30 @@ Run the `theme selector: toggle` action in the command palette to see a current
}
```

### Entry Spacing

- Description: Spacing between worktree entries
- Setting: `entry_spacing`
- Default: `comfortable`

**Options**

1. Comfortable entry spacing

```json
{
"entry_spacing": "comfortable"
}
```

2. Compact entry spacing

```json
{
"entry_spacing": "compact"
}
```

### Git Status

- Description: Indicates newly created and updated files
Expand Down

0 comments on commit 2a9d755

Please sign in to comment.