fix(activity): virtualize the Activity list
- Build only the slots near the viewport (viewport + 300 px margin), spacers above and below, same pattern as the calls list - Fixed row height 58 px (natural was 58.45) and header height 30 px, look unchanged - Name lookups only for visible rows - Collapse a match arm flagged by clippy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -109,11 +109,9 @@ impl ActivityCenter {
109
109
match event {
110
110
AppEvent::Activity => self.reload(cx),
111
111
AppEvent::Selection => self.on_selection(cx),
112
AppEvent::Messages(conversation_id) => {
113
if self.in_foreground(conversation_id, cx) {
114
let conversation_id = conversation_id.clone();
115
self.mark_read_where(|entry| entry.conversation_id == conversation_id, cx);
116
}
112
AppEvent::Messages(conversation_id) if self.in_foreground(conversation_id, cx) => {
113
let conversation_id = conversation_id.clone();
114
self.mark_read_where(|entry| entry.conversation_id == conversation_id, cx);
117
115
}
118
116
_ => {}
119
117
}
@@ -109,11 +109,9 @@ impl ActivityCenter {109
match event {109
match event {110
AppEvent::Activity => self.reload(cx),110
AppEvent::Activity => self.reload(cx),111
AppEvent::Selection => self.on_selection(cx),111
AppEvent::Selection => self.on_selection(cx),112
AppEvent::Messages(conversation_id) => {112
AppEvent::Messages(conversation_id) if self.in_foreground(conversation_id, cx) => {113
if self.in_foreground(conversation_id, cx) {113
let conversation_id = conversation_id.clone();114
let conversation_id = conversation_id.clone();114
self.mark_read_where(|entry| entry.conversation_id == conversation_id, cx);115
self.mark_read_where(|entry| entry.conversation_id == conversation_id, cx);116
}117
}115
}118
_ => {}116
_ => {}119
}117
}@@ -1,4 +1,5 @@
1
1
use std::collections::{HashMap, HashSet};
2
use std::ops::Range;
2
3
use std::rc::Rc;
3
4
4
5
use chrono::{DateTime, Local, NaiveDate, Offset};
@@ -9,7 +10,7 @@ use gpui_kit::*;
9
10
use store::Sidebar;
10
11
11
12
use super::avatar::person_avatar;
12
use super::scroll_edge::with_top_edge;
13
use super::scroll_edge::{scroll_offset, with_top_edge};
13
14
use super::sidebar::SIDEBAR_SCROLL_DIVIDER;
14
15
use super::widgets::{Corner, corner_badge, dot, icon};
15
16
use crate::activity::{ActivityCenter, Entry, Filter, Kind};
@@ -27,6 +28,11 @@ const AVATAR_SIZE: f32 = 32.;
27
28
const KIND_MARKER_SIZE: f32 = 16.;
28
29
const BUTTON_SIZE: f32 = 32.;
29
30
const MARK_READ_SIZE: f32 = 20.;
31
const ROW_HEIGHT: f32 = 58.;
32
const HEADER_HEIGHT: f32 = 30.;
33
const EMPTY_HEIGHT: f32 = 84.;
34
const FALLBACK_VIEWPORT: f32 = 900.;
35
const VIEWPORT_MARGIN: f32 = 300.;
30
36
const FILTER_KEY: &str = "activity_filter";
31
37
const PROPOSALS_LABEL: &str = "Agent proposals";
32
38
pub const ACTIVITY_PROPOSALS_TAG: &str = "shell/islands/sidebar/activity-proposals";
@@ -285,6 +291,8 @@ fn row_frame(parts: RowParts) -> Stateful<Div> {
285
291
.id(ElementId::Name(element_id.clone().into()))
286
292
.debug_selector(move || selector)
287
293
.group(group.clone())
294
.h(px(ROW_HEIGHT))
295
.flex_none()
288
296
.mx(px(6.))
289
297
.px(px(10.))
290
298
.py(px(8.))
@@ -550,7 +558,7 @@ fn conversation_label(sidebar: &Sidebar, conversation_id: &str) -> Option<String
550
558
551
559
fn group_header(label: &'static str) -> Div {
552
560
div()
553
.h(px(26.))
561
.h(px(HEADER_HEIGHT - 4.))
554
562
.mt(px(4.))
555
563
.px(px(16.))
556
564
.flex()
@@ -562,8 +570,62 @@ fn group_header(label: &'static str) -> Div {
562
570
.child(label)
563
571
}
564
572
573
enum Slot<'a> {
574
Proposals(Vec<PendingProposal>),
575
Header(&'static str),
576
Row(&'a Entry),
577
Empty,
578
}
579
580
impl Slot<'_> {
581
fn height(&self) -> f32 {
582
match self {
583
Slot::Proposals(proposals) => HEADER_HEIGHT + proposals.len() as f32 * ROW_HEIGHT,
584
Slot::Header(_) => HEADER_HEIGHT,
585
Slot::Row(_) => ROW_HEIGHT,
586
Slot::Empty => EMPTY_HEIGHT,
587
}
588
}
589
}
590
591
#[derive(Debug, PartialEq)]
592
struct VisibleSlots {
593
range: Range<usize>,
594
before: f32,
595
after: f32,
596
}
597
598
fn visible_slots(heights: &[f32], from: f32, to: f32) -> VisibleSlots {
599
let mut position = 0.;
600
let mut first = heights.len();
601
let mut last = heights.len();
602
let mut before = 0.;
603
for (index, height) in heights.iter().enumerate() {
604
let end = position + height;
605
if first == heights.len() && end >= from {
606
first = index;
607
before = position;
608
}
609
if position > to {
610
last = index;
611
break;
612
}
613
position = end;
614
}
615
if first == heights.len() {
616
before = position;
617
}
618
let last = last.max(first);
619
let after = heights[last..].iter().sum();
620
VisibleSlots {
621
range: first..last,
622
before,
623
after,
624
}
625
}
626
565
627
impl Render for ActivityPanel {
566
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
628
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
567
629
let now: DateTime<Local> = Local::now();
568
630
let (today, offset) = (now.date_naive(), now.offset().fix());
569
631
let panel = cx.entity();
@@ -574,10 +636,38 @@ impl Render for ActivityPanel {
574
636
.read(cx)
575
637
.feed()
576
638
.sections(self.filter, today, offset);
577
let unresolved: Vec<String> = sections
639
let mut slots: Vec<Slot> = Vec::new();
640
let proposals: Vec<PendingProposal> = agent_api::pending_proposals(cx)
641
.into_iter()
642
.filter(|pending| admits_proposal(self.filter, pending))
643
.collect();
644
if !proposals.is_empty() {
645
slots.push(Slot::Proposals(proposals));
646
}
647
for section in §ions {
648
slots.push(Slot::Header(section.bucket.label()));
649
slots.extend(section.entries.iter().map(|entry| Slot::Row(entry)));
650
}
651
if slots.is_empty() {
652
slots.push(Slot::Empty);
653
}
654
let heights: Vec<f32> = slots.iter().map(Slot::height).collect();
655
let top = -f32::from(scroll_offset(&self.scroll).y);
656
let measured = f32::from(self.scroll.bounds().size.height);
657
let height = if measured > 1. {
658
measured
659
} else {
660
f32::from(window.viewport_size().height).max(FALLBACK_VIEWPORT)
661
};
662
let visible = visible_slots(&heights, top - VIEWPORT_MARGIN, top + height + VIEWPORT_MARGIN);
663
let visible_slots = &slots[visible.range.clone()];
664
let unresolved: Vec<String> = visible_slots
578
665
.iter()
579
.flat_map(|section| section.entries.iter())
580
.flat_map(|entry| entry.unresolved_user_ids())
666
.filter_map(|slot| match slot {
667
Slot::Row(entry) => Some(entry.unresolved_user_ids()),
668
_ => None,
669
})
670
.flatten()
581
671
.filter(|user_id| !self.looked_up.contains(*user_id))
582
672
.cloned()
583
673
.collect();
@@ -587,44 +677,41 @@ impl Render for ActivityPanel {
587
677
.extend(resolve_names(state, &unresolved));
588
678
}
589
679
let mut rows: Vec<AnyElement> = Vec::new();
590
let proposal_rows: Vec<AnyElement> = agent_api::pending_proposals(cx)
591
.iter()
592
.filter(|pending| admits_proposal(self.filter, pending))
593
.map(|pending| self.proposal_row(pending, &state.sidebar, today, offset, panel.clone()))
594
.collect();
595
if !proposal_rows.is_empty() {
596
rows.push(
597
v_flex()
680
if visible.before > 0. {
681
rows.push(div().h(px(visible.before)).flex_none().into_any_element());
682
}
683
for slot in visible_slots {
684
rows.push(match slot {
685
Slot::Proposals(proposals) => v_flex()
598
686
.debug_selector(|| ACTIVITY_PROPOSALS_TAG.into())
599
687
.child(group_header(PROPOSALS_LABEL))
600
.children(proposal_rows)
688
.children(proposals.iter().map(|pending| {
689
self.proposal_row(pending, &state.sidebar, today, offset, panel.clone())
690
}))
601
691
.into_any_element(),
602
);
603
}
604
for section in sections {
605
rows.push(group_header(section.bucket.label()).into_any_element());
606
for entry in section.entries {
607
rows.push(self.row(
692
Slot::Header(label) => group_header(label).into_any_element(),
693
Slot::Row(entry) => self.row(
608
694
entry,
609
695
&state.sidebar,
610
696
&state.directory,
611
697
today,
612
698
offset,
613
699
panel.clone(),
614
));
615
}
616
}
617
if rows.is_empty() {
618
rows.push(
619
div()
620
.py(px(32.))
700
),
701
Slot::Empty => div()
702
.h(px(EMPTY_HEIGHT))
621
703
.flex()
704
.flex_none()
705
.items_center()
622
706
.justify_center()
623
707
.text_size(px(13.))
624
708
.text_color(theme::text_muted())
625
709
.child(self.filter.empty_label())
626
710
.into_any_element(),
627
);
711
});
712
}
713
if visible.after > 0. {
714
rows.push(div().h(px(visible.after)).flex_none().into_any_element());
628
715
}
629
716
let list = v_flex()
630
717
.id("activity-list")
@@ -651,7 +738,9 @@ mod tests {
651
738
use gpui_kit::{AppContext as _, Modifiers, TestAppContext};
652
739
use store::{ChatRecord, Sidebar, Store};
653
740
654
use super::{ActivityPanel, detail, headline};
741
use super::{
742
ActivityPanel, ROW_HEIGHT, VIEWPORT_MARGIN, VisibleSlots, detail, headline, visible_slots,
743
};
655
744
use crate::activity::{ActivityCenter, Actor, Entry, Filter, Kind};
656
745
use crate::app_state::{AppState, Mode};
657
746
@@ -681,6 +770,33 @@ mod tests {
681
770
}
682
771
}
683
772
773
#[test]
774
fn only_rows_near_the_viewport_are_built() {
775
let heights = vec![ROW_HEIGHT; 300];
776
let viewport = 900.;
777
let at_top = visible_slots(&heights, -VIEWPORT_MARGIN, viewport + VIEWPORT_MARGIN);
778
assert_eq!(
779
at_top,
780
VisibleSlots {
781
range: 0..21,
782
before: 0.,
783
after: 279. * ROW_HEIGHT,
784
}
785
);
786
let scrolled = visible_slots(
787
&heights,
788
5000. - VIEWPORT_MARGIN,
789
5000. + viewport + VIEWPORT_MARGIN,
790
);
791
assert_eq!(scrolled.range, 81..107);
792
assert_eq!(scrolled.before, 81. * ROW_HEIGHT);
793
assert_eq!(scrolled.after, 193. * ROW_HEIGHT);
794
let past_the_end = visible_slots(&heights, 90_000., 91_000.);
795
assert_eq!(past_the_end.range, 300..300);
796
assert_eq!(past_the_end.before, 300. * ROW_HEIGHT);
797
assert_eq!(past_the_end.after, 0.);
798
}
799
684
800
#[test]
685
801
fn detail_follows_the_kind() {
686
802
assert_eq!(detail(&entry(Kind::Mention, 1)), "hello");
@@ -1,4 +1,5 @@1
use std::collections::{HashMap, HashSet};1
use std::collections::{HashMap, HashSet};2
use std::ops::Range;2
use std::rc::Rc;3
use std::rc::Rc;3
4
4
use chrono::{DateTime, Local, NaiveDate, Offset};5
use chrono::{DateTime, Local, NaiveDate, Offset};@@ -9,7 +10,7 @@ use gpui_kit::*;9
use store::Sidebar;10
use store::Sidebar;10
11
11
use super::avatar::person_avatar;12
use super::avatar::person_avatar;12
use super::scroll_edge::with_top_edge;13
use super::scroll_edge::{scroll_offset, with_top_edge};13
use super::sidebar::SIDEBAR_SCROLL_DIVIDER;14
use super::sidebar::SIDEBAR_SCROLL_DIVIDER;14
use super::widgets::{Corner, corner_badge, dot, icon};15
use super::widgets::{Corner, corner_badge, dot, icon};15
use crate::activity::{ActivityCenter, Entry, Filter, Kind};16
use crate::activity::{ActivityCenter, Entry, Filter, Kind};@@ -27,6 +28,11 @@ const AVATAR_SIZE: f32 = 32.;27
const KIND_MARKER_SIZE: f32 = 16.;28
const KIND_MARKER_SIZE: f32 = 16.;28
const BUTTON_SIZE: f32 = 32.;29
const BUTTON_SIZE: f32 = 32.;29
const MARK_READ_SIZE: f32 = 20.;30
const MARK_READ_SIZE: f32 = 20.;31
const ROW_HEIGHT: f32 = 58.;32
const HEADER_HEIGHT: f32 = 30.;33
const EMPTY_HEIGHT: f32 = 84.;34
const FALLBACK_VIEWPORT: f32 = 900.;35
const VIEWPORT_MARGIN: f32 = 300.;30
const FILTER_KEY: &str = "activity_filter";36
const FILTER_KEY: &str = "activity_filter";31
const PROPOSALS_LABEL: &str = "Agent proposals";37
const PROPOSALS_LABEL: &str = "Agent proposals";32
pub const ACTIVITY_PROPOSALS_TAG: &str = "shell/islands/sidebar/activity-proposals";38
pub const ACTIVITY_PROPOSALS_TAG: &str = "shell/islands/sidebar/activity-proposals";@@ -285,6 +291,8 @@ fn row_frame(parts: RowParts) -> Stateful<Div> {285
.id(ElementId::Name(element_id.clone().into()))291
.id(ElementId::Name(element_id.clone().into()))286
.debug_selector(move || selector)292
.debug_selector(move || selector)287
.group(group.clone())293
.group(group.clone())294
.h(px(ROW_HEIGHT))295
.flex_none()288
.mx(px(6.))296
.mx(px(6.))289
.px(px(10.))297
.px(px(10.))290
.py(px(8.))298
.py(px(8.))@@ -550,7 +558,7 @@ fn conversation_label(sidebar: &Sidebar, conversation_id: &str) -> Option<String550
558
551
fn group_header(label: &'static str) -> Div {559
fn group_header(label: &'static str) -> Div {552
div()560
div()553
.h(px(26.))561
.h(px(HEADER_HEIGHT - 4.))554
.mt(px(4.))562
.mt(px(4.))555
.px(px(16.))563
.px(px(16.))556
.flex()564
.flex()@@ -562,8 +570,62 @@ fn group_header(label: &'static str) -> Div {562
.child(label)570
.child(label)563
}571
}564
572
573
enum Slot<'a> {574
Proposals(Vec<PendingProposal>),575
Header(&'static str),576
Row(&'a Entry),577
Empty,578
}579
580
impl Slot<'_> {581
fn height(&self) -> f32 {582
match self {583
Slot::Proposals(proposals) => HEADER_HEIGHT + proposals.len() as f32 * ROW_HEIGHT,584
Slot::Header(_) => HEADER_HEIGHT,585
Slot::Row(_) => ROW_HEIGHT,586
Slot::Empty => EMPTY_HEIGHT,587
}588
}589
}590
591
#[derive(Debug, PartialEq)]592
struct VisibleSlots {593
range: Range<usize>,594
before: f32,595
after: f32,596
}597
598
fn visible_slots(heights: &[f32], from: f32, to: f32) -> VisibleSlots {599
let mut position = 0.;600
let mut first = heights.len();601
let mut last = heights.len();602
let mut before = 0.;603
for (index, height) in heights.iter().enumerate() {604
let end = position + height;605
if first == heights.len() && end >= from {606
first = index;607
before = position;608
}609
if position > to {610
last = index;611
break;612
}613
position = end;614
}615
if first == heights.len() {616
before = position;617
}618
let last = last.max(first);619
let after = heights[last..].iter().sum();620
VisibleSlots {621
range: first..last,622
before,623
after,624
}625
}626
565
impl Render for ActivityPanel {627
impl Render for ActivityPanel {566
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {628
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {567
let now: DateTime<Local> = Local::now();629
let now: DateTime<Local> = Local::now();568
let (today, offset) = (now.date_naive(), now.offset().fix());630
let (today, offset) = (now.date_naive(), now.offset().fix());569
let panel = cx.entity();631
let panel = cx.entity();@@ -574,10 +636,38 @@ impl Render for ActivityPanel {574
.read(cx)636
.read(cx)575
.feed()637
.feed()576
.sections(self.filter, today, offset);638
.sections(self.filter, today, offset);577
let unresolved: Vec<String> = sections639
let mut slots: Vec<Slot> = Vec::new();640
let proposals: Vec<PendingProposal> = agent_api::pending_proposals(cx)641
.into_iter()642
.filter(|pending| admits_proposal(self.filter, pending))643
.collect();644
if !proposals.is_empty() {645
slots.push(Slot::Proposals(proposals));646
}647
for section in §ions {648
slots.push(Slot::Header(section.bucket.label()));649
slots.extend(section.entries.iter().map(|entry| Slot::Row(entry)));650
}651
if slots.is_empty() {652
slots.push(Slot::Empty);653
}654
let heights: Vec<f32> = slots.iter().map(Slot::height).collect();655
let top = -f32::from(scroll_offset(&self.scroll).y);656
let measured = f32::from(self.scroll.bounds().size.height);657
let height = if measured > 1. {658
measured659
} else {660
f32::from(window.viewport_size().height).max(FALLBACK_VIEWPORT)661
};662
let visible = visible_slots(&heights, top - VIEWPORT_MARGIN, top + height + VIEWPORT_MARGIN);663
let visible_slots = &slots[visible.range.clone()];664
let unresolved: Vec<String> = visible_slots578
.iter()665
.iter()579
.flat_map(|section| section.entries.iter())666
.filter_map(|slot| match slot {580
.flat_map(|entry| entry.unresolved_user_ids())667
Slot::Row(entry) => Some(entry.unresolved_user_ids()),668
_ => None,669
})670
.flatten()581
.filter(|user_id| !self.looked_up.contains(*user_id))671
.filter(|user_id| !self.looked_up.contains(*user_id))582
.cloned()672
.cloned()583
.collect();673
.collect();@@ -587,44 +677,41 @@ impl Render for ActivityPanel {587
.extend(resolve_names(state, &unresolved));677
.extend(resolve_names(state, &unresolved));588
}678
}589
let mut rows: Vec<AnyElement> = Vec::new();679
let mut rows: Vec<AnyElement> = Vec::new();590
let proposal_rows: Vec<AnyElement> = agent_api::pending_proposals(cx)680
if visible.before > 0. {591
.iter()681
rows.push(div().h(px(visible.before)).flex_none().into_any_element());592
.filter(|pending| admits_proposal(self.filter, pending))682
}593
.map(|pending| self.proposal_row(pending, &state.sidebar, today, offset, panel.clone()))683
for slot in visible_slots {594
.collect();684
rows.push(match slot {595
if !proposal_rows.is_empty() {685
Slot::Proposals(proposals) => v_flex()596
rows.push(597
v_flex()598
.debug_selector(|| ACTIVITY_PROPOSALS_TAG.into())686
.debug_selector(|| ACTIVITY_PROPOSALS_TAG.into())599
.child(group_header(PROPOSALS_LABEL))687
.child(group_header(PROPOSALS_LABEL))600
.children(proposal_rows)688
.children(proposals.iter().map(|pending| {689
self.proposal_row(pending, &state.sidebar, today, offset, panel.clone())690
}))601
.into_any_element(),691
.into_any_element(),602
);692
Slot::Header(label) => group_header(label).into_any_element(),603
}693
Slot::Row(entry) => self.row(604
for section in sections {605
rows.push(group_header(section.bucket.label()).into_any_element());606
for entry in section.entries {607
rows.push(self.row(608
entry,694
entry,609
&state.sidebar,695
&state.sidebar,610
&state.directory,696
&state.directory,611
today,697
today,612
offset,698
offset,613
panel.clone(),699
panel.clone(),614
));700
),615
}701
Slot::Empty => div()616
}702
.h(px(EMPTY_HEIGHT))617
if rows.is_empty() {618
rows.push(619
div()620
.py(px(32.))621
.flex()703
.flex()704
.flex_none()705
.items_center()622
.justify_center()706
.justify_center()623
.text_size(px(13.))707
.text_size(px(13.))624
.text_color(theme::text_muted())708
.text_color(theme::text_muted())625
.child(self.filter.empty_label())709
.child(self.filter.empty_label())626
.into_any_element(),710
.into_any_element(),627
);711
});712
}713
if visible.after > 0. {714
rows.push(div().h(px(visible.after)).flex_none().into_any_element());628
}715
}629
let list = v_flex()716
let list = v_flex()630
.id("activity-list")717
.id("activity-list")@@ -651,7 +738,9 @@ mod tests {651
use gpui_kit::{AppContext as _, Modifiers, TestAppContext};738
use gpui_kit::{AppContext as _, Modifiers, TestAppContext};652
use store::{ChatRecord, Sidebar, Store};739
use store::{ChatRecord, Sidebar, Store};653
740
654
use super::{ActivityPanel, detail, headline};741
use super::{742
ActivityPanel, ROW_HEIGHT, VIEWPORT_MARGIN, VisibleSlots, detail, headline, visible_slots,743
};655
use crate::activity::{ActivityCenter, Actor, Entry, Filter, Kind};744
use crate::activity::{ActivityCenter, Actor, Entry, Filter, Kind};656
use crate::app_state::{AppState, Mode};745
use crate::app_state::{AppState, Mode};657
746
@@ -681,6 +770,33 @@ mod tests {681
}770
}682
}771
}683
772
773
#[test]774
fn only_rows_near_the_viewport_are_built() {775
let heights = vec![ROW_HEIGHT; 300];776
let viewport = 900.;777
let at_top = visible_slots(&heights, -VIEWPORT_MARGIN, viewport + VIEWPORT_MARGIN);778
assert_eq!(779
at_top,780
VisibleSlots {781
range: 0..21,782
before: 0.,783
after: 279. * ROW_HEIGHT,784
}785
);786
let scrolled = visible_slots(787
&heights,788
5000. - VIEWPORT_MARGIN,789
5000. + viewport + VIEWPORT_MARGIN,790
);791
assert_eq!(scrolled.range, 81..107);792
assert_eq!(scrolled.before, 81. * ROW_HEIGHT);793
assert_eq!(scrolled.after, 193. * ROW_HEIGHT);794
let past_the_end = visible_slots(&heights, 90_000., 91_000.);795
assert_eq!(past_the_end.range, 300..300);796
assert_eq!(past_the_end.before, 300. * ROW_HEIGHT);797
assert_eq!(past_the_end.after, 0.);798
}799
684
#[test]800
#[test]685
fn detail_follows_the_kind() {801
fn detail_follows_the_kind() {686
assert_eq!(detail(&entry(Kind::Mention, 1)), "hello");802
assert_eq!(detail(&entry(Kind::Mention, 1)), "hello");