BlueGit

ict rusty-teams

Merge remote-tracking branch 'origin/main' into feat/outlook-reminders

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
18d4ea612ff3b576bbb73ea599edb24117a3803a
3 files changed +105 −10
crates/app/src/views/conversation.rs +8 −3
@@ -40,6 +40,7 @@ use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_
40 40 use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
41 41 use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};
42 42 use super::post_card::render_post;
43 use super::pin_banner::{pin_banner_inset, pin_banner_overlay};
43 44 use super::profile_card::opens_profile;
44 45 use super::reaction_picker::{PickHandler, ReactionPicker};
45 46 use super::reaction_pills::{ReactionControls, ReactionPopover};
@@ -3400,6 +3401,9 @@ impl Render for ConversationView {
3400 3401 agent_runs: self.agent_runs.clone(),
3401 3402 reaction_proposals: self.reaction_proposals.clone(),
3402 3403 };
3404 let pin_banner = self
3405 .render_pin_banner(cx)
3406 .filter(|_| !drafting && !self.shared_active() && !self.recap_active());
3403 3407 let scroller = MessageScroller::new(
3404 3408 "messages",
3405 3409 self.scroller.clone(),
@@ -3495,7 +3499,8 @@ impl Render for ConversationView {
3495 3499 view.update(cx, |this, cx| this.leave_detached(cx)).ok();
3496 3500 })
3497 3501 })
3498 .with_bottom_fade(background);
3502 .with_bottom_fade(background)
3503 .with_top_inset(pin_banner_inset(pin_banner.is_some()));
3499 3504
3500 3505 root = match self.current.as_ref().filter(|_| !drafting) {
3501 3506 Some(current) => root.child(self.render_header(current, cx)),
@@ -3505,7 +3510,6 @@ impl Render for ConversationView {
3505 3510 .render_tab_bar(window, cx)
3506 3511 .or_else(|| self.render_meeting_tab_bar(cx));
3507 3512 root = root.children(tab_bar.filter(|_| !drafting));
3508 root = root.children(self.render_pin_banner(cx).filter(|_| !drafting));
3509 3513 let sync_failed = self
3510 3514 .current
3511 3515 .as_ref()
@@ -3571,7 +3575,8 @@ impl Render for ConversationView {
3571 3575 .on_scroll_wheel(
3572 3576 cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
3573 3577 )
3574 .child(body),
3578 .child(body)
3579 .children(pin_banner.map(pin_banner_overlay)),
3575 3580 )
3576 3581 .children(self.render_draft_error(cx))
3577 3582 .when(!in_feed && !recap_active, |column| {
@@ -40,6 +40,7 @@ use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_
40use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
40use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
41use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};
41use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};
42use super::post_card::render_post;
42use super::post_card::render_post;
43use super::pin_banner::{pin_banner_inset, pin_banner_overlay};
43use super::profile_card::opens_profile;
44use super::profile_card::opens_profile;
44use super::reaction_picker::{PickHandler, ReactionPicker};
45use super::reaction_picker::{PickHandler, ReactionPicker};
45use super::reaction_pills::{ReactionControls, ReactionPopover};
46use super::reaction_pills::{ReactionControls, ReactionPopover};
@@ -3400,6 +3401,9 @@ impl Render for ConversationView {
3400 agent_runs: self.agent_runs.clone(),
3401 agent_runs: self.agent_runs.clone(),
3401 reaction_proposals: self.reaction_proposals.clone(),
3402 reaction_proposals: self.reaction_proposals.clone(),
3402 };
3403 };
3404 let pin_banner = self
3405 .render_pin_banner(cx)
3406 .filter(|_| !drafting && !self.shared_active() && !self.recap_active());
3403 let scroller = MessageScroller::new(
3407 let scroller = MessageScroller::new(
3404 "messages",
3408 "messages",
3405 self.scroller.clone(),
3409 self.scroller.clone(),
@@ -3495,7 +3499,8 @@ impl Render for ConversationView {
3495 view.update(cx, |this, cx| this.leave_detached(cx)).ok();
3499 view.update(cx, |this, cx| this.leave_detached(cx)).ok();
3496 })
3500 })
3497 })
3501 })
3498 .with_bottom_fade(background);
3502 .with_bottom_fade(background)
3503 .with_top_inset(pin_banner_inset(pin_banner.is_some()));
3499
3504
3500 root = match self.current.as_ref().filter(|_| !drafting) {
3505 root = match self.current.as_ref().filter(|_| !drafting) {
3501 Some(current) => root.child(self.render_header(current, cx)),
3506 Some(current) => root.child(self.render_header(current, cx)),
@@ -3505,7 +3510,6 @@ impl Render for ConversationView {
3505 .render_tab_bar(window, cx)
3510 .render_tab_bar(window, cx)
3506 .or_else(|| self.render_meeting_tab_bar(cx));
3511 .or_else(|| self.render_meeting_tab_bar(cx));
3507 root = root.children(tab_bar.filter(|_| !drafting));
3512 root = root.children(tab_bar.filter(|_| !drafting));
3508 root = root.children(self.render_pin_banner(cx).filter(|_| !drafting));
3509 let sync_failed = self
3513 let sync_failed = self
3510 .current
3514 .current
3511 .as_ref()
3515 .as_ref()
@@ -3571,7 +3575,8 @@ impl Render for ConversationView {
3571 .on_scroll_wheel(
3575 .on_scroll_wheel(
3572 cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
3576 cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
3573 )
3577 )
3574 .child(body),
3578 .child(body)
3579 .children(pin_banner.map(pin_banner_overlay)),
3575 )
3580 )
3576 .children(self.render_draft_error(cx))
3581 .children(self.render_draft_error(cx))
3577 .when(!in_feed && !recap_active, |column| {
3582 .when(!in_feed && !recap_active, |column| {
crates/app/src/views/pin_banner.rs +29 −4
@@ -8,6 +8,8 @@ use super::widgets::icon;
8 8 use crate::theme;
9 9
10 10 const BANNER_HEIGHT: f32 = 40.;
11 const BANNER_MARGIN: f32 = 20.;
12 const BANNER_GAP: f32 = 8.;
11 13 const BANNER_PADDING: f32 = 12.;
12 14 const BUTTON_SIZE: f32 = 28.;
13 15 const FALLBACK_PREVIEW: &str = "Pinned message";
@@ -26,6 +28,20 @@ pub struct PinBannerActions {
26 28 pub unpin: Action,
27 29 }
28 30
31 pub fn pin_banner_inset(shown: bool) -> Pixels {
32 px(if shown { BANNER_HEIGHT + BANNER_GAP } else { 0. })
33 }
34
35 pub fn pin_banner_overlay(banner: AnyElement) -> AnyElement {
36 div()
37 .absolute()
38 .top_0()
39 .left(px(BANNER_MARGIN))
40 .right(px(BANNER_MARGIN))
41 .child(banner)
42 .into_any_element()
43 }
44
29 45 pub fn cycle_pin(index: usize, length: usize, delta: isize) -> usize {
30 46 if length == 0 {
31 47 return 0;
@@ -71,16 +87,18 @@ pub fn render_pin_banner(data: PinBannerData, actions: PinBannerActions) -> AnyE
71 87 h_flex()
72 88 .id("pin-banner")
73 89 .group("pin-banner")
90 .occlude()
91 .w_full()
74 92 .h(px(BANNER_HEIGHT))
75 .flex_none()
76 .mx(px(20.))
77 .mb(px(8.))
78 93 .pl(px(BANNER_PADDING))
79 94 .pr(px(6.))
80 95 .gap(px(8.))
81 96 .items_center()
82 97 .rounded(px(8.))
98 .border_1()
99 .border_color(theme::border())
83 100 .bg(theme::row_hover())
101 .shadow(theme::toast_shadow())
84 102 .cursor_pointer()
85 103 .hover(|banner| banner.bg(theme::surface_raised()))
86 104 .on_click(move |_, window, cx| open(window, cx))
@@ -134,7 +152,8 @@ pub fn render_pin_banner(data: PinBannerData, actions: PinBannerActions) -> AnyE
134 152
135 153 #[cfg(test)]
136 154 mod tests {
137 use super::{cycle_pin, position_label};
155 use super::{BANNER_HEIGHT, cycle_pin, pin_banner_inset, position_label};
156 use gpui_kit::px;
138 157
139 158 #[test]
140 159 fn cycling_wraps_around_both_ends() {
@@ -151,6 +170,12 @@ mod tests {
151 170 assert_eq!(cycle_pin(0, 1, -1), 0);
152 171 }
153 172
173 #[test]
174 fn inset_clears_the_banner_only_while_it_shows() {
175 assert!(pin_banner_inset(true) > px(BANNER_HEIGHT));
176 assert_eq!(pin_banner_inset(false), px(0.));
177 }
178
154 179 #[test]
155 180 fn position_is_one_based() {
156 181 assert_eq!(position_label(0, 3), "1 of 3");
@@ -8,6 +8,8 @@ use super::widgets::icon;
8use crate::theme;
8use crate::theme;
9
9
10const BANNER_HEIGHT: f32 = 40.;
10const BANNER_HEIGHT: f32 = 40.;
11const BANNER_MARGIN: f32 = 20.;
12const BANNER_GAP: f32 = 8.;
11const BANNER_PADDING: f32 = 12.;
13const BANNER_PADDING: f32 = 12.;
12const BUTTON_SIZE: f32 = 28.;
14const BUTTON_SIZE: f32 = 28.;
13const FALLBACK_PREVIEW: &str = "Pinned message";
15const FALLBACK_PREVIEW: &str = "Pinned message";
@@ -26,6 +28,20 @@ pub struct PinBannerActions {
26 pub unpin: Action,
28 pub unpin: Action,
27}
29}
28
30
31pub fn pin_banner_inset(shown: bool) -> Pixels {
32 px(if shown { BANNER_HEIGHT + BANNER_GAP } else { 0. })
33}
34
35pub fn pin_banner_overlay(banner: AnyElement) -> AnyElement {
36 div()
37 .absolute()
38 .top_0()
39 .left(px(BANNER_MARGIN))
40 .right(px(BANNER_MARGIN))
41 .child(banner)
42 .into_any_element()
43}
44
29pub fn cycle_pin(index: usize, length: usize, delta: isize) -> usize {
45pub fn cycle_pin(index: usize, length: usize, delta: isize) -> usize {
30 if length == 0 {
46 if length == 0 {
31 return 0;
47 return 0;
@@ -71,16 +87,18 @@ pub fn render_pin_banner(data: PinBannerData, actions: PinBannerActions) -> AnyE
71 h_flex()
87 h_flex()
72 .id("pin-banner")
88 .id("pin-banner")
73 .group("pin-banner")
89 .group("pin-banner")
90 .occlude()
91 .w_full()
74 .h(px(BANNER_HEIGHT))
92 .h(px(BANNER_HEIGHT))
75 .flex_none()
76 .mx(px(20.))
77 .mb(px(8.))
78 .pl(px(BANNER_PADDING))
93 .pl(px(BANNER_PADDING))
79 .pr(px(6.))
94 .pr(px(6.))
80 .gap(px(8.))
95 .gap(px(8.))
81 .items_center()
96 .items_center()
82 .rounded(px(8.))
97 .rounded(px(8.))
98 .border_1()
99 .border_color(theme::border())
83 .bg(theme::row_hover())
100 .bg(theme::row_hover())
101 .shadow(theme::toast_shadow())
84 .cursor_pointer()
102 .cursor_pointer()
85 .hover(|banner| banner.bg(theme::surface_raised()))
103 .hover(|banner| banner.bg(theme::surface_raised()))
86 .on_click(move |_, window, cx| open(window, cx))
104 .on_click(move |_, window, cx| open(window, cx))
@@ -134,7 +152,8 @@ pub fn render_pin_banner(data: PinBannerData, actions: PinBannerActions) -> AnyE
134
152
135#[cfg(test)]
153#[cfg(test)]
136mod tests {
154mod tests {
137 use super::{cycle_pin, position_label};
155 use super::{BANNER_HEIGHT, cycle_pin, pin_banner_inset, position_label};
156 use gpui_kit::px;
138
157
139 #[test]
158 #[test]
140 fn cycling_wraps_around_both_ends() {
159 fn cycling_wraps_around_both_ends() {
@@ -151,6 +170,12 @@ mod tests {
151 assert_eq!(cycle_pin(0, 1, -1), 0);
170 assert_eq!(cycle_pin(0, 1, -1), 0);
152 }
171 }
153
172
173 #[test]
174 fn inset_clears_the_banner_only_while_it_shows() {
175 assert!(pin_banner_inset(true) > px(BANNER_HEIGHT));
176 assert_eq!(pin_banner_inset(false), px(0.));
177 }
178
154 #[test]
179 #[test]
155 fn position_is_one_based() {
180 fn position_is_one_based() {
156 assert_eq!(position_label(0, 3), "1 of 3");
181 assert_eq!(position_label(0, 3), "1 of 3");
vendor/gpui-component/src/message_scroller.rs +68 −3
@@ -25,6 +25,8 @@ const BOTTOM_FADE_TRANSITION: Duration = Duration::from_millis(200);
25 25 /// [`MessageScroller::new`].
26 26 pub struct MessageScrollerState {
27 27 list_state: ListState,
28 top_inset: gpui::Pixels,
29 inset_scroll_pending: bool,
28 30 }
29 31
30 32 impl MessageScrollerState {
@@ -46,7 +48,11 @@ impl MessageScrollerState {
46 48 });
47 49 });
48 50
49 Self { list_state }
51 Self {
52 list_state,
53 top_inset: px(0.),
54 inset_scroll_pending: false,
55 }
50 56 }
51 57
52 58 /// Return the current number of rows known by the virtual list.
@@ -135,7 +141,7 @@ impl MessageScrollerState {
135 141 true
136 142 }
137 143
138 /// Scroll to the row at `index`, if it exists.
144 /// Scroll to the row at `index`, if it exists, below the top inset.
139 145 pub fn scroll_to_item(&mut self, index: usize, cx: &mut Context<Self>) -> bool {
140 146 if index >= self.list_state.item_count() {
141 147 return false;
@@ -145,10 +151,30 @@ impl MessageScrollerState {
145 151 item_ix: index,
146 152 offset_in_item: px(0.),
147 153 });
154 self.inset_scroll_pending = index > 0 && self.top_inset > px(0.);
148 155 cx.notify();
149 156 true
150 157 }
151 158
159 /// Return the space kept free above the first row.
160 pub fn top_inset(&self) -> gpui::Pixels {
161 self.top_inset
162 }
163
164 fn sync_top_inset(&mut self, inset: gpui::Pixels) {
165 if self.top_inset == inset {
166 return;
167 }
168 self.top_inset = inset;
169 if self.list_state.item_count() > 0 {
170 self.list_state.remeasure_items(0..1);
171 }
172 }
173
174 fn take_inset_scroll(&mut self) -> Option<gpui::Pixels> {
175 std::mem::take(&mut self.inset_scroll_pending).then_some(self.top_inset)
176 }
177
152 178 /// Stop following the tail until the next reset or `scroll_to_end`.
153 179 pub fn stop_following(&mut self) {
154 180 self.list_state.set_follow_mode(FollowMode::Normal);
@@ -180,6 +206,7 @@ pub struct MessageScroller {
180 206 jump_button_renderer: Option<Box<dyn FnOnce(Button) -> Button>>,
181 207 jump_button_transition: Duration,
182 208 bottom_fade: Option<Hsla>,
209 top_inset: gpui::Pixels,
183 210 scrollbar: bool,
184 211 jump_button: bool,
185 212 force_jump_button: bool,
@@ -212,6 +239,7 @@ impl MessageScroller {
212 239 jump_button_renderer: None,
213 240 jump_button_transition: JUMP_BUTTON_TRANSITION,
214 241 bottom_fade: None,
242 top_inset: px(0.),
215 243 scrollbar: true,
216 244 jump_button: true,
217 245 force_jump_button: false,
@@ -306,6 +334,16 @@ impl MessageScroller {
306 334 self.bottom_fade = Some(color.into());
307 335 self
308 336 }
337
338 /// Keep `inset` free above the first row for an overlay at the top.
339 ///
340 /// The rows scroll behind the overlay, and the inset scrolls with the
341 /// content, so the first row can still be scrolled out from under it.
342 /// [`MessageScrollerState::scroll_to_item`] lands rows below the inset.
343 pub fn with_top_inset(mut self, inset: gpui::Pixels) -> Self {
344 self.top_inset = inset;
345 self
346 }
309 347 }
310 348
311 349 impl Styled for MessageScroller {
@@ -346,6 +384,21 @@ impl RenderOnce for MessageScroller {
346 384 } else {
347 385 0.
348 386 };
387 let top_inset = self.top_inset;
388 let inset_scroll = self.state.update(cx, |state, _| {
389 state.sync_top_inset(top_inset);
390 state.take_inset_scroll()
391 });
392 // The rows above the target are only measured by the layout of this
393 // frame, so the step back by the inset waits for the next one.
394 if let Some(inset) = inset_scroll {
395 let list_state = list_state.clone();
396 let state = self.state.clone();
397 window.on_next_frame(move |_, cx| {
398 list_state.scroll_by(-inset);
399 state.update(cx, |_, cx| cx.notify());
400 });
401 }
349 402 let tokens = cx.theme().semantic_tokens();
350 403 let row_style = self.row_style;
351 404 let jump_button_style = self.jump_button_style;
@@ -374,6 +427,7 @@ impl RenderOnce for MessageScroller {
374 427 .when_some(row_inset_left, |this, left| this.pl(left))
375 428 .when_some(row_inset_right, |this, right| this.pr(right))
376 429 .refine_style(&row_style)
430 .when(index == 0 && top_inset > px(0.), |this| this.pt(top_inset))
377 431 .child(renderer(index, window, cx))
378 432 .into_any_element()
379 433 })
@@ -495,6 +549,15 @@ mod tests {
495 549 assert!(state.remeasure_items(0..6, cx));
496 550 assert!(!state.remeasure_items(6..7, cx));
497 551 assert!(state.scroll_to_item(2, cx));
552 assert_eq!(state.take_inset_scroll(), None);
553 state.sync_top_inset(px(48.));
554 assert_eq!(state.top_inset(), px(48.));
555 assert!(state.scroll_to_item(2, cx));
556 assert_eq!(state.take_inset_scroll(), Some(px(48.)));
557 assert_eq!(state.take_inset_scroll(), None);
558 assert!(state.scroll_to_item(0, cx));
559 assert_eq!(state.take_inset_scroll(), None);
560 assert!(state.scroll_to_item(2, cx));
498 561 assert!(!state.is_scrolled_up());
499 562 assert!(!state.is_following_tail());
500 563 state.scroll_to_end(cx);
@@ -519,7 +582,8 @@ mod tests {
519 582 .with_jump_button_style(StyleRefinement::default())
520 583 .with_jump_button_renderer(|button| button.large())
521 584 .with_jump_button_transition(Duration::from_millis(300))
522 .with_bottom_fade(gpui::white());
585 .with_bottom_fade(gpui::white())
586 .with_top_inset(px(48.));
523 587
524 588 assert!(!scroller.scrollbar);
525 589 assert!(!scroller.jump_button);
@@ -527,5 +591,6 @@ mod tests {
527 591 assert!(scroller.jump_button_renderer.is_some());
528 592 assert_eq!(scroller.jump_button_transition, Duration::from_millis(300));
529 593 assert_eq!(scroller.bottom_fade, Some(gpui::white()));
594 assert_eq!(scroller.top_inset, px(48.));
530 595 }
531 596 }
@@ -25,6 +25,8 @@ const BOTTOM_FADE_TRANSITION: Duration = Duration::from_millis(200);
25/// [`MessageScroller::new`].
25/// [`MessageScroller::new`].
26pub struct MessageScrollerState {
26pub struct MessageScrollerState {
27 list_state: ListState,
27 list_state: ListState,
28 top_inset: gpui::Pixels,
29 inset_scroll_pending: bool,
28}
30}
29
31
30impl MessageScrollerState {
32impl MessageScrollerState {
@@ -46,7 +48,11 @@ impl MessageScrollerState {
46 });
48 });
47 });
49 });
48
50
49 Self { list_state }
51 Self {
52 list_state,
53 top_inset: px(0.),
54 inset_scroll_pending: false,
55 }
50 }
56 }
51
57
52 /// Return the current number of rows known by the virtual list.
58 /// Return the current number of rows known by the virtual list.
@@ -135,7 +141,7 @@ impl MessageScrollerState {
135 true
141 true
136 }
142 }
137
143
138 /// Scroll to the row at `index`, if it exists.
144 /// Scroll to the row at `index`, if it exists, below the top inset.
139 pub fn scroll_to_item(&mut self, index: usize, cx: &mut Context<Self>) -> bool {
145 pub fn scroll_to_item(&mut self, index: usize, cx: &mut Context<Self>) -> bool {
140 if index >= self.list_state.item_count() {
146 if index >= self.list_state.item_count() {
141 return false;
147 return false;
@@ -145,10 +151,30 @@ impl MessageScrollerState {
145 item_ix: index,
151 item_ix: index,
146 offset_in_item: px(0.),
152 offset_in_item: px(0.),
147 });
153 });
154 self.inset_scroll_pending = index > 0 && self.top_inset > px(0.);
148 cx.notify();
155 cx.notify();
149 true
156 true
150 }
157 }
151
158
159 /// Return the space kept free above the first row.
160 pub fn top_inset(&self) -> gpui::Pixels {
161 self.top_inset
162 }
163
164 fn sync_top_inset(&mut self, inset: gpui::Pixels) {
165 if self.top_inset == inset {
166 return;
167 }
168 self.top_inset = inset;
169 if self.list_state.item_count() > 0 {
170 self.list_state.remeasure_items(0..1);
171 }
172 }
173
174 fn take_inset_scroll(&mut self) -> Option<gpui::Pixels> {
175 std::mem::take(&mut self.inset_scroll_pending).then_some(self.top_inset)
176 }
177
152 /// Stop following the tail until the next reset or `scroll_to_end`.
178 /// Stop following the tail until the next reset or `scroll_to_end`.
153 pub fn stop_following(&mut self) {
179 pub fn stop_following(&mut self) {
154 self.list_state.set_follow_mode(FollowMode::Normal);
180 self.list_state.set_follow_mode(FollowMode::Normal);
@@ -180,6 +206,7 @@ pub struct MessageScroller {
180 jump_button_renderer: Option<Box<dyn FnOnce(Button) -> Button>>,
206 jump_button_renderer: Option<Box<dyn FnOnce(Button) -> Button>>,
181 jump_button_transition: Duration,
207 jump_button_transition: Duration,
182 bottom_fade: Option<Hsla>,
208 bottom_fade: Option<Hsla>,
209 top_inset: gpui::Pixels,
183 scrollbar: bool,
210 scrollbar: bool,
184 jump_button: bool,
211 jump_button: bool,
185 force_jump_button: bool,
212 force_jump_button: bool,
@@ -212,6 +239,7 @@ impl MessageScroller {
212 jump_button_renderer: None,
239 jump_button_renderer: None,
213 jump_button_transition: JUMP_BUTTON_TRANSITION,
240 jump_button_transition: JUMP_BUTTON_TRANSITION,
214 bottom_fade: None,
241 bottom_fade: None,
242 top_inset: px(0.),
215 scrollbar: true,
243 scrollbar: true,
216 jump_button: true,
244 jump_button: true,
217 force_jump_button: false,
245 force_jump_button: false,
@@ -306,6 +334,16 @@ impl MessageScroller {
306 self.bottom_fade = Some(color.into());
334 self.bottom_fade = Some(color.into());
307 self
335 self
308 }
336 }
337
338 /// Keep `inset` free above the first row for an overlay at the top.
339 ///
340 /// The rows scroll behind the overlay, and the inset scrolls with the
341 /// content, so the first row can still be scrolled out from under it.
342 /// [`MessageScrollerState::scroll_to_item`] lands rows below the inset.
343 pub fn with_top_inset(mut self, inset: gpui::Pixels) -> Self {
344 self.top_inset = inset;
345 self
346 }
309}
347}
310
348
311impl Styled for MessageScroller {
349impl Styled for MessageScroller {
@@ -346,6 +384,21 @@ impl RenderOnce for MessageScroller {
346 } else {
384 } else {
347 0.
385 0.
348 };
386 };
387 let top_inset = self.top_inset;
388 let inset_scroll = self.state.update(cx, |state, _| {
389 state.sync_top_inset(top_inset);
390 state.take_inset_scroll()
391 });
392 // The rows above the target are only measured by the layout of this
393 // frame, so the step back by the inset waits for the next one.
394 if let Some(inset) = inset_scroll {
395 let list_state = list_state.clone();
396 let state = self.state.clone();
397 window.on_next_frame(move |_, cx| {
398 list_state.scroll_by(-inset);
399 state.update(cx, |_, cx| cx.notify());
400 });
401 }
349 let tokens = cx.theme().semantic_tokens();
402 let tokens = cx.theme().semantic_tokens();
350 let row_style = self.row_style;
403 let row_style = self.row_style;
351 let jump_button_style = self.jump_button_style;
404 let jump_button_style = self.jump_button_style;
@@ -374,6 +427,7 @@ impl RenderOnce for MessageScroller {
374 .when_some(row_inset_left, |this, left| this.pl(left))
427 .when_some(row_inset_left, |this, left| this.pl(left))
375 .when_some(row_inset_right, |this, right| this.pr(right))
428 .when_some(row_inset_right, |this, right| this.pr(right))
376 .refine_style(&row_style)
429 .refine_style(&row_style)
430 .when(index == 0 && top_inset > px(0.), |this| this.pt(top_inset))
377 .child(renderer(index, window, cx))
431 .child(renderer(index, window, cx))
378 .into_any_element()
432 .into_any_element()
379 })
433 })
@@ -495,6 +549,15 @@ mod tests {
495 assert!(state.remeasure_items(0..6, cx));
549 assert!(state.remeasure_items(0..6, cx));
496 assert!(!state.remeasure_items(6..7, cx));
550 assert!(!state.remeasure_items(6..7, cx));
497 assert!(state.scroll_to_item(2, cx));
551 assert!(state.scroll_to_item(2, cx));
552 assert_eq!(state.take_inset_scroll(), None);
553 state.sync_top_inset(px(48.));
554 assert_eq!(state.top_inset(), px(48.));
555 assert!(state.scroll_to_item(2, cx));
556 assert_eq!(state.take_inset_scroll(), Some(px(48.)));
557 assert_eq!(state.take_inset_scroll(), None);
558 assert!(state.scroll_to_item(0, cx));
559 assert_eq!(state.take_inset_scroll(), None);
560 assert!(state.scroll_to_item(2, cx));
498 assert!(!state.is_scrolled_up());
561 assert!(!state.is_scrolled_up());
499 assert!(!state.is_following_tail());
562 assert!(!state.is_following_tail());
500 state.scroll_to_end(cx);
563 state.scroll_to_end(cx);
@@ -519,7 +582,8 @@ mod tests {
519 .with_jump_button_style(StyleRefinement::default())
582 .with_jump_button_style(StyleRefinement::default())
520 .with_jump_button_renderer(|button| button.large())
583 .with_jump_button_renderer(|button| button.large())
521 .with_jump_button_transition(Duration::from_millis(300))
584 .with_jump_button_transition(Duration::from_millis(300))
522 .with_bottom_fade(gpui::white());
585 .with_bottom_fade(gpui::white())
586 .with_top_inset(px(48.));
523
587
524 assert!(!scroller.scrollbar);
588 assert!(!scroller.scrollbar);
525 assert!(!scroller.jump_button);
589 assert!(!scroller.jump_button);
@@ -527,5 +591,6 @@ mod tests {
527 assert!(scroller.jump_button_renderer.is_some());
591 assert!(scroller.jump_button_renderer.is_some());
528 assert_eq!(scroller.jump_button_transition, Duration::from_millis(300));
592 assert_eq!(scroller.jump_button_transition, Duration::from_millis(300));
529 assert_eq!(scroller.bottom_fade, Some(gpui::white()));
593 assert_eq!(scroller.bottom_fade, Some(gpui::white()));
594 assert_eq!(scroller.top_inset, px(48.));
530 }
595 }
531}
596}