list: Fix incorrect selected item background color (#1648)

It will mix `accent` and `list_active` before.
This commit is contained in:
Floyd Wang 2025-11-20 16:46:57 +08:00 committed by GitHub
parent b6dace13cc
commit d55125149b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 28 deletions

View file

@ -4,7 +4,7 @@ use fake::Fake;
use gpui::{
App, AppContext, Context, ElementId, Entity, FocusHandle, Focusable, InteractiveElement,
IntoElement, ParentElement, Render, RenderOnce, ScrollStrategy, SharedString, Styled,
Subscription, Task, Timer, Window, actions, div, prelude::FluentBuilder as _, px,
Subscription, Task, Timer, Window, actions, div, px,
};
use gpui_component::{
@ -46,22 +46,15 @@ impl Company {
#[derive(IntoElement)]
struct CompanyListItem {
base: ListItem,
ix: IndexPath,
company: Rc<Company>,
selected: bool,
}
impl CompanyListItem {
pub fn new(
id: impl Into<ElementId>,
company: Rc<Company>,
ix: IndexPath,
selected: bool,
) -> Self {
pub fn new(id: impl Into<ElementId>, company: Rc<Company>, selected: bool) -> Self {
CompanyListItem {
company,
ix,
base: ListItem::new(id),
base: ListItem::new(id).selected(selected),
selected,
}
}
@ -92,24 +85,11 @@ impl RenderOnce for CompanyListItem {
_ => cx.theme().foreground,
};
let bg_color = if self.selected {
cx.theme().list_active
} else if self.ix.row % 2 == 0 {
cx.theme().list
} else {
cx.theme().list_even
};
self.base
.px_2()
.py_1()
.overflow_x_hidden()
.bg(bg_color)
.border_1()
.border_color(bg_color)
.when(self.selected, |this| {
this.border_color(cx.theme().list_active_border)
})
.rounded(cx.theme().radius)
.child(
h_flex()
@ -293,7 +273,7 @@ impl ListDelegate for CompanyListDelegate {
fn render_item(&self, ix: IndexPath, _: &mut Window, _: &mut App) -> Option<Self::Item> {
let selected = Some(ix) == self.selected_index || Some(ix) == self.confirmed_index;
if let Some(company) = self.matched_companies[ix.section].get(ix.row) {
return Some(CompanyListItem::new(ix, company.clone(), ix, selected));
return Some(CompanyListItem::new(ix, company.clone(), selected));
}
None

View file

@ -203,16 +203,19 @@ impl RenderOnce for ListItem {
.when_some(self.suffix, |this, suffix| this.child(suffix(window, cx)))
.map(|this| {
if is_selectable && (self.selected || self.secondary_selected) {
this.bg(cx.theme().accent).child(
let bg = if self.selected {
cx.theme().list_active
} else {
cx.theme().accent
};
this.bg(bg).child(
div()
.absolute()
.top_0()
.left_0()
.right_0()
.bottom_0()
.when(!self.secondary_selected, |this| {
this.bg(cx.theme().list_active)
})
.border_1()
.border_color(cx.theme().list_active_border)
.refine_style(&selected_style),