Skip to content

Commit

Permalink
Fix git colors in image tabs (zed-industries#21773)
Browse files Browse the repository at this point in the history
Note that the git coloring of the icons got removed in
zed-industries#21383

Closes zed-industries#21772

Release Notes:

- N/A
  • Loading branch information
nilskch authored Dec 10, 2024
1 parent 44164db commit bd20876
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/image_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ doctest = false
[dependencies]
anyhow.workspace = true
db.workspace = true
editor.workspace = true
file_icons.workspace = true
gpui.workspace = true
project.workspace = true
Expand Down
22 changes: 18 additions & 4 deletions crates/image_viewer/src/image_viewer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use anyhow::Context as _;
use editor::items::entry_git_aware_label_color;
use gpui::{
canvas, div, fill, img, opaque_grey, point, size, AnyElement, AppContext, Bounds, EventEmitter,
FocusHandle, FocusableView, InteractiveElement, IntoElement, Model, ObjectFit, ParentElement,
Expand Down Expand Up @@ -94,15 +95,28 @@ impl Item for ImageView {
}

fn tab_content(&self, params: TabContentParams, cx: &WindowContext) -> AnyElement {
let path = self.image_item.read(cx).file.path();
let title = path
let project_path = self.image_item.read(cx).project_path(cx);
let label_color = if ItemSettings::get_global(cx).git_status {
self.project
.read(cx)
.entry_for_path(&project_path, cx)
.map(|entry| {
entry_git_aware_label_color(entry.git_status, entry.is_ignored, params.selected)
})
.unwrap_or_else(|| params.text_color())
} else {
params.text_color()
};

let title = project_path
.path
.file_name()
.unwrap_or_else(|| path.as_os_str())
.unwrap_or_else(|| project_path.path.as_os_str())
.to_string_lossy()
.to_string();
Label::new(title)
.single_line()
.color(params.text_color())
.color(label_color)
.italic(params.preview)
.into_any_element()
}
Expand Down

0 comments on commit bd20876

Please sign in to comment.