Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix transparent Threads Sidebar backgrounds in some themes (#65343)
roboin8f41da25202e
diff --git a/crates/agent_ui/src/threads_archive_view.rs b/crates/agent_ui/src/threads_archive_view.rsindex fd1f69de8c7..da6c5ddc4ef 100644--- a/crates/agent_ui/src/threads_archive_view.rs+++ b/crates/agent_ui/src/threads_archive_view.rs@@ -663,6 +663,7 @@ impl ThreadsArchiveView {let archived_color = Color::Custom(cx.theme().colors().icon_muted.opacity(0.6));let base = ThreadItem::new(id, thread.display_title())+ .base_bg(cx.theme().colors().panel_background).icon(icon).when(is_archived, |this| {this.archived(true)diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rsindex 235e32980e1..edf18fc6365 100644--- a/crates/sidebar/src/sidebar.rs+++ b/crates/sidebar/src/sidebar.rs@@ -2350,9 +2350,9 @@ impl Sidebar {let color = cx.theme().colors();let sidebar_base_bg = if is_sticky {- color.surface_overlay_background()+ color.panel_background_for_overlay()} else {- color.surface_background+ color.panel_background};// The fade gradient renders as a visible patch on transparent windows,@@ -3292,7 +3292,7 @@ impl Sidebar {.unwrap_or(px(0.));let color = cx.theme().colors();- let background = color.surface_overlay_background();+ let background = color.panel_background_for_overlay();let element = v_flex().absolute()@@ -6281,7 +6281,7 @@ impl Sidebar {let id = SharedString::from(format!("thread-entry-{}", ix));let color = cx.theme().colors();- let sidebar_bg = color.surface_background;+ let sidebar_bg = color.panel_background;let button_hover_bg = color.element_background;let button_active_bg = color.element_active;@@ -6610,7 +6610,7 @@ impl Sidebar {let timestamp = format_history_entry_timestamp(terminal.metadata.created_at);let is_hovered = self.hovered_thread_index == Some(ix);let color = cx.theme().colors();- let sidebar_bg = color.surface_background;+ let sidebar_bg = color.panel_background;let button_hover_bg = color.element_background;let button_active_bg = color.element_active;let metadata = terminal.metadata.clone();@@ -7952,7 +7952,7 @@ impl Render for Sidebar {let sticky_header = self.render_sticky_header(window, cx);let color = cx.theme().colors();- let bg = color.surface_background;+ let bg = color.background.blend(color.panel_background);let no_open_projects = !self.contents.has_open_projects;let no_search_results = self.contents.entries.is_empty();diff --git a/crates/sidebar/src/sidebar_tests.rs b/crates/sidebar/src/sidebar_tests.rsindex 307ff52d208..dc1a7c81bcb 100644--- a/crates/sidebar/src/sidebar_tests.rs+++ b/crates/sidebar/src/sidebar_tests.rs@@ -707,6 +707,33 @@ fn visible_entries_as_strings(})}+#[gpui::test]+async fn test_sidebar_background_with_transparent_panel(cx: &mut TestAppContext) {+ let (_, project) = init_multi_project_test(&["/my-project"], cx).await;+ let (multi_workspace, cx) =+ cx.add_window_view(|window, cx| MultiWorkspace::test_new(project, window, cx));+ let sidebar = setup_sidebar(&multi_workspace, cx);++ for panel_alpha in [0.0, 0.4] {+ set_sidebar_test_panel_alpha(panel_alpha, cx);+ let background = cx.update(|_, cx| {+ let colors = cx.theme().colors();+ colors.background.blend(colors.panel_background)+ });+ cx.draw(+ gpui::point(px(0.), px(0.)),+ gpui::size(px(400.), px(240.)),+ |_, _| sidebar.clone().into_any_element(),+ );++ cx.update(|window, _| {+ let quads = window.painted_quads();+ let sidebar_background = quads.first().expect("Sidebar should paint its background");+ assert_eq!(sidebar_background.background.as_solid(), Some(background));+ });+ }+}+#[gpui::test]async fn test_sidebar_action_hover_contrasts_with_row(cx: &mut TestAppContext) {let project = init_test_project_with_agent_panel("/my-project", cx).await;@@ -716,8 +743,8 @@ async fn test_sidebar_action_hover_contrasts_with_row(cx: &mut TestAppContext) {let (sidebar, _panel) = setup_sidebar_with_agent_panel(&multi_workspace, cx);save_n_test_threads(1, &project, cx).await;- for (query, surface_alpha) in [("my-project", 1.0), ("", 1.0), ("", 0.0), ("", 0.2)] {- set_sidebar_test_surface_alpha(surface_alpha, cx);+ for (query, panel_alpha) in [("my-project", 1.0), ("", 1.0), ("", 0.0), ("", 0.2)] {+ set_sidebar_test_panel_alpha(panel_alpha, cx);type_in_search(&sidebar, query, cx);let row_bounds = sidebar.read_with(cx, |sidebar, _| {sidebar@@ -779,8 +806,8 @@ async fn test_sidebar_action_hover_contrasts_with_row(cx: &mut TestAppContext) {.bounds.map(|value| px(value.as_f32() / window.scale_factor()))});- for surface_alpha in [1.0, 0.0, 0.2] {- set_sidebar_test_surface_alpha(surface_alpha, cx);+ for panel_alpha in [1.0, 0.0, 0.2] {+ set_sidebar_test_panel_alpha(panel_alpha, cx);assert_sidebar_action_hover(selector, row_bounds, cx);}}@@ -15824,11 +15851,12 @@ async fn test_find_or_create_workspace_returns_the_created_remote_workspace();}-fn set_sidebar_test_surface_alpha(alpha: f32, cx: &mut VisualTestContext) {+fn set_sidebar_test_panel_alpha(alpha: f32, cx: &mut VisualTestContext) {cx.update(|window, cx| {let mut theme = cx.theme().as_ref().clone();theme.styles.colors.background = Hsla::from(gpui::rgb(0xdcdcdd));- theme.styles.colors.surface_background = Hsla::from(gpui::rgb(0xebebec)).alpha(alpha);+ theme.styles.colors.surface_background = Hsla::from(gpui::rgb(0xff00ff));+ theme.styles.colors.panel_background = Hsla::from(gpui::rgb(0xebebec)).alpha(alpha);theme.styles.colors.element_background = Hsla::from(gpui::rgb(0xebebec));theme.styles.colors.ghost_element_hover = Hsla::from(gpui::rgb(0xdfdfe0));theme::GlobalTheme::update_theme(cx, Arc::new(theme));diff --git a/crates/theme/src/styles/colors.rs b/crates/theme/src/styles/colors.rsindex c6109c1c196..e0adbc7b563 100644--- a/crates/theme/src/styles/colors.rs+++ b/crates/theme/src/styles/colors.rs@@ -463,9 +463,9 @@ pub enum ThemeColorField {}impl ThemeColors {- pub fn surface_overlay_background(&self) -> Hsla {- if self.background.a >= 1.0 || self.surface_background.a >= 1.0 {- self.background.blend(self.surface_background)+ pub fn panel_background_for_overlay(&self) -> Hsla {+ if self.background.a >= 1.0 || self.panel_background.a >= 1.0 {+ self.background.blend(self.panel_background)} else {self.panel_overlay_background}@@ -649,11 +649,11 @@ mod tests {use super::*;#[test]- fn surface_overlay_background() {+ fn panel_background_for_overlay() {let mut colors = ThemeColors::light();colors.panel_overlay_background = Hsla::from(gpui::rgb(0xff0000));- for (surface, background, expected) in [+ for (panel, background, expected) in [(0x58585a00, 0xdcdcddff, 0xdcdcddff),(0x00000080, 0xdcdcddff, 0x6d6d6eff),(0xebebecff, 0x24252900, 0xebebecff),@@ -661,12 +661,12 @@ mod tests {(0xebebec00, 0x24252980, 0xff0000ff),(0x24252980, 0x24252980, 0xff0000ff),] {- colors.surface_background = Hsla::from(gpui::rgba(surface));+ colors.panel_background = Hsla::from(gpui::rgba(panel));colors.background = Hsla::from(gpui::rgba(background));assert_eq!(- u32::from(Rgba::from(colors.surface_overlay_background())),+ u32::from(Rgba::from(colors.panel_background_for_overlay())),expected,- "surface {surface:#010x}, background {background:#010x}"+ "panel {panel:#010x}, background {background:#010x}");}}