Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Display file icons in tabs (#14523)

Marshall Bowers1818fef32f24
diff --git a/Cargo.lock b/Cargo.lock
index 472ac875e04..123e5fc9d71 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13335,6 +13335,7 @@ dependencies = [
"derive_more",
"dev_server_projects",
"env_logger",
+ "file_icons",
"fs",
"futures 0.3.28",
"gpui",
diff --git a/assets/settings/default.json b/assets/settings/default.json
index 2e741b3c68f..4a1bcfc0ed7 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -431,7 +431,9 @@
// Show git status colors in the editor tabs.
"git_status": false,
// Position of the close button on the editor tabs.
- "close_position": "right"
+ "close_position": "right",
+ // Whether to show the file icon for a tab.
+ "file_icons": true
},
// Settings related to preview tabs.
"preview_tabs": {
diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.toml
index 2b178d50dde..e04449f14ba 100644
--- a/crates/workspace/Cargo.toml
+++ b/crates/workspace/Cargo.toml
@@ -36,6 +36,7 @@ clock.workspace = true
collections.workspace = true
db.workspace = true
derive_more.workspace = true
+file_icons.workspace = true
fs.workspace = true
futures.workspace = true
gpui.workspace = true
diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs
index 5da2c5a5efb..fc63249934b 100644
--- a/crates/workspace/src/item.rs
+++ b/crates/workspace/src/item.rs
@@ -39,6 +39,7 @@ pub const LEADER_UPDATE_THROTTLE: Duration = Duration::from_millis(200);
pub struct ItemSettings {
pub git_status: bool,
pub close_position: ClosePosition,
+ pub file_icons: bool,
}
#[derive(Deserialize)]
@@ -75,6 +76,10 @@ pub struct ItemSettingsContent {
///
/// Default: right
close_position: Option<ClosePosition>,
+ /// Whether to show the file icon for a tab.
+ ///
+ /// Default: true
+ file_icons: Option<bool>,
}
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs
index 087cfd6bef6..c4802764b7d 100644
--- a/crates/workspace/src/pane.rs
+++ b/crates/workspace/src/pane.rs
@@ -10,6 +10,7 @@ use crate::{
};
use anyhow::Result;
use collections::{BTreeSet, HashMap, HashSet, VecDeque};
+use file_icons::FileIcons;
use futures::{stream::FuturesUnordered, StreamExt};
use gpui::{
actions, anchored, deferred, impl_actions, prelude::*, Action, AnchorCorner, AnyElement,
@@ -1595,6 +1596,14 @@ impl Pane {
let is_last_item = ix == self.items.len() - 1;
let position_relative_to_active_item = ix.cmp(&self.active_item_index);
+ let file_icon = ItemSettings::get_global(cx)
+ .file_icons
+ .then(|| {
+ item.project_path(cx)
+ .and_then(|path| FileIcons::get_icon(path.path.as_ref(), cx))
+ })
+ .flatten();
+
let tab = Tab::new(ix)
.position(if is_first_item {
TabPosition::First
@@ -1663,7 +1672,18 @@ impl Pane {
.when_some(item.tab_tooltip_text(cx), |tab, text| {
tab.tooltip(move |cx| Tooltip::text(text.clone(), cx))
})
- .start_slot::<Indicator>(indicator)
+ .map(|tab| match indicator {
+ Some(indicator) => tab.start_slot(indicator),
+ None => tab.start_slot::<Icon>(file_icon.map(|icon| {
+ Icon::from_path(icon.to_string())
+ .size(IconSize::XSmall)
+ .color(if is_active {
+ Color::Default
+ } else {
+ Color::Muted
+ })
+ })),
+ })
.end_slot(
IconButton::new("close tab", IconName::Close)
.shape(IconButtonShape::Square)
diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.md
index dd95993cbbe..ef7cf261d09 100644
--- a/docs/src/configuring-zed.md
+++ b/docs/src/configuring-zed.md
@@ -435,6 +435,7 @@ List of `string` values
```json
"tabs": {
"close_position": "right",
+ "file_icons": true,
"git_status": false
},
```
@@ -463,6 +464,12 @@ List of `string` values
}
```
+### File Icons
+
+- Description: Whether to show the file icon for a tab.
+- Setting: `file_icons`
+- Default: `true`
+
### Git Status
- Description: Whether or not to show Git file status in tab.