BlueGit

ict rusty-teams

feat(chat): typing indicator as part of the chat

- Avatar plus dots bubble right under the last message, sticks above the composer once that message scrolls away
- No grey fade above the composer and no empty line reserved for typing; messages end cleanly at the composer edge
- Deviation from Teams (line above the input): asked for by Daniel, closer to iMessage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-11 · 2 weeks ago

Hash
c07a9d0afc0f4cadaec5c76d0650033e025b6a88
Parent
987f0c4d
3 files changed +83 −24
crates/app/src/views/conversation.rs +77 −24
@@ -143,7 +143,11 @@ const SLOW_AFTER: Duration = Duration::from_secs(8);
143 143 const PROGRESS_MIN_VISIBLE: Duration = Duration::from_millis(500);
144 144 const PROGRESS_BAR_PERIOD: Duration = Duration::from_millis(1400);
145 145 const PROGRESS_BAR_WIDTH: f32 = 0.35;
146 const TYPING_LINE_HEIGHT: f32 = 22.;
146 const TYPING_BUBBLE_HEIGHT: f32 = 28.;
147 const TYPING_BUBBLE_PADDING: f32 = 12.;
148 const TYPING_SIDE_INSET: f32 = 20.;
149 const TYPING_BOTTOM_GAP: f32 = 8.;
150 pub const TYPING_TAG: &str = "shell/islands/main/typing";
147 151 const TYPING_DOT_SIZE: f32 = 5.;
148 152 const TYPING_DOT_COUNT: usize = 3;
149 153 const TYPING_PULSE_PERIOD: Duration = Duration::from_millis(1200);
@@ -862,7 +866,10 @@ impl ConversationView {
862 866 }
863 867 }
864 868
865 fn render_typing_line(&self, cx: &App) -> impl IntoElement {
869 fn render_typing_line(&self, cx: &App) -> Option<AnyElement> {
870 if self.in_feed() {
871 return None;
872 }
866 873 let app = self.app.read(cx);
867 874 let faces = self
868 875 .current
@@ -870,18 +877,17 @@ impl ConversationView {
870 877 .filter(|_| !self.draft_active)
871 878 .map(|current| app.typing.faces(current.selection.conversation_id()))
872 879 .unwrap_or_default();
880 if faces.is_empty() {
881 return None;
882 }
873 883 let tooltip_text = typing_tooltip(
874 884 &faces
875 885 .iter()
876 886 .map(|face| face.name.clone())
877 887 .collect::<Vec<_>>(),
878 888 );
879 let flat = matches!(
880 self.current.as_ref().map(|current| &current.mode),
881 Some(ViewMode::Flat)
882 );
883 889 let faces_element = match faces.as_slice() {
884 [face] if flat => person_avatar(
890 [face] => person_avatar(
885 891 &app.directory,
886 892 face.user_id.as_deref(),
887 893 &face.name,
@@ -889,27 +895,33 @@ impl ConversationView {
889 895 ),
890 896 _ => member_stack(&app.directory, &faces, faces.len(), true).into_any_element(),
891 897 };
892 h_flex()
893 .h(px(if flat {
894 AVATAR_SIZE + 4.
895 } else {
896 TYPING_LINE_HEIGHT
897 }))
898 .flex_none()
899 .px(px(20.))
900 .gap(px(if flat { AVATAR_GAP } else { 6. }))
901 .items_center()
902 .when(!faces.is_empty(), |line| {
903 line.child(
898 Some(
899 h_flex()
900 .debug_selector(|| TYPING_TAG.into())
901 .h(px(TYPING_BUBBLE_HEIGHT))
902 .px(px(TYPING_SIDE_INSET))
903 .gap(px(AVATAR_GAP))
904 .items_center()
905 .child(
904 906 div()
905 907 .id("typing-faces")
908 .flex_none()
906 909 .tooltip(move |window, cx| {
907 910 Tooltip::new(tooltip_text.clone()).build(window, cx)
908 911 })
909 912 .child(faces_element),
910 913 )
911 .child(typing_dots())
912 })
914 .child(
915 h_flex()
916 .h_full()
917 .px(px(TYPING_BUBBLE_PADDING))
918 .items_center()
919 .rounded_full()
920 .bg(theme::surface_raised())
921 .child(typing_dots()),
922 )
923 .into_any_element(),
924 )
913 925 }
914 926
915 927 fn open(&mut self, selection: Selection, window: &mut Window, cx: &mut Context<Self>) {
@@ -3981,6 +3993,15 @@ impl Render for ConversationView {
3981 3993 let timeline_top_inset = pin_banner_inset(pin_banner.is_some());
3982 3994 let comfy = self.app.read(cx).account_chat_settings().message_density
3983 3995 != teams_core::MessageDensity::Compact;
3996 let typing_line = self.render_typing_line(cx);
3997 let typing_offset = {
3998 let scroller = self.scroller.read(cx);
3999 let last_row = scroller.item_count().checked_sub(1);
4000 typing_bottom_offset(
4001 self.timeline_bounds.get(),
4002 last_row.and_then(|index| scroller.item_bounds(index)),
4003 )
4004 };
3984 4005 let scroller = MessageScroller::new(
3985 4006 "messages",
3986 4007 self.scroller.clone(),
@@ -4097,7 +4118,11 @@ impl Render for ConversationView {
4097 4118 view.update(cx, |this, cx| this.leave_detached(cx)).ok();
4098 4119 })
4099 4120 })
4100 .with_bottom_fade(background)
4121 .when(typing_line.is_some(), |scroller| {
4122 scroller.with_list_style(
4123 StyleRefinement::default().pb(px(TYPING_BUBBLE_HEIGHT + 2. * TYPING_BOTTOM_GAP)),
4124 )
4125 })
4101 4126 .with_top_inset(timeline_top_inset);
4102 4127
4103 4128 root = match self.current.as_ref().filter(|_| !drafting) {
@@ -4195,6 +4220,14 @@ impl Render for ConversationView {
4195 4220 .child(record_bounds(&self.timeline_bounds, timeline_top_inset))
4196 4221 .on_scroll_wheel(cx.listener(|this, _, _, cx| this.close_reaction_details(cx)))
4197 4222 .child(body)
4223 .children(typing_line.map(|line| {
4224 div()
4225 .absolute()
4226 .left_0()
4227 .right_0()
4228 .bottom(px(typing_offset))
4229 .child(runway(line, comfy))
4230 }))
4198 4231 .when(feed_scrolled, |timeline| {
4199 4232 timeline.child(
4200 4233 edge_divider(FEED_EDGE_TAG)
@@ -4216,7 +4249,6 @@ impl Render for ConversationView {
4216 4249 None => column.child(runway(
4217 4250 v_flex()
4218 4251 .w_full()
4219 .child(self.render_typing_line(cx))
4220 4252 .children(self.render_proposal_card(cx))
4221 4253 .child(self.composer.clone()),
4222 4254 comfy,
@@ -4275,6 +4307,17 @@ impl Render for ConversationView {
4275 4307 }
4276 4308 }
4277 4309
4310 /// Right under the last row like one more message; once that row scrolls below the view it sticks above the composer.
4311 fn typing_bottom_offset(timeline: Option<Bounds<Pixels>>, last_row: Option<Bounds<Pixels>>) -> f32 {
4312 let (Some(timeline), Some(last_row)) = (timeline, last_row) else {
4313 return TYPING_BOTTOM_GAP;
4314 };
4315 let under_last_row = f32::from(timeline.bottom() - last_row.bottom())
4316 - TYPING_BOTTOM_GAP
4317 - TYPING_BUBBLE_HEIGHT;
4318 under_last_row.max(TYPING_BOTTOM_GAP)
4319 }
4320
4278 4321 fn typing_dots() -> impl IntoElement {
4279 4322 h_flex()
4280 4323 .gap(px(3.))
@@ -4370,7 +4413,7 @@ fn runway(content: impl IntoElement, comfy: bool) -> AnyElement {
4370 4413 mod tests {
4371 4414 use std::sync::Arc;
4372 4415
4373 use super::{DropTarget, drop_overlay_text};
4416 use super::{DropTarget, drop_overlay_text, typing_bottom_offset};
4374 4417
4375 4418 use gpui_kit::test::TestWindowExt as _;
4376 4419 use gpui_kit::{AppContext as _, TestAppContext, WindowOptions};
@@ -4504,4 +4547,14 @@ mod tests {
4504 4547 assert_eq!(state.selection, Some(crate::demo::first_selection()));
4505 4548 });
4506 4549 }
4550
4551 #[test]
4552 fn the_typing_bubble_follows_the_last_row_and_sticks_above_the_composer() {
4553 use gpui_kit::{Bounds, point, px, size};
4554 let timeline = Bounds::new(point(px(0.), px(100.)), size(px(800.), px(600.)));
4555 let row_ending_at = |bottom: f32| Some(Bounds::new(point(px(0.), px(bottom - 50.)), size(px(800.), px(50.))));
4556 assert_eq!(typing_bottom_offset(Some(timeline), row_ending_at(400.)), 264.);
4557 assert_eq!(typing_bottom_offset(Some(timeline), row_ending_at(900.)), 8.);
4558 assert_eq!(typing_bottom_offset(Some(timeline), None), 8.);
4559 }
4507 4560 }
@@ -143,7 +143,11 @@ const SLOW_AFTER: Duration = Duration::from_secs(8);
143const PROGRESS_MIN_VISIBLE: Duration = Duration::from_millis(500);
143const PROGRESS_MIN_VISIBLE: Duration = Duration::from_millis(500);
144const PROGRESS_BAR_PERIOD: Duration = Duration::from_millis(1400);
144const PROGRESS_BAR_PERIOD: Duration = Duration::from_millis(1400);
145const PROGRESS_BAR_WIDTH: f32 = 0.35;
145const PROGRESS_BAR_WIDTH: f32 = 0.35;
146const TYPING_LINE_HEIGHT: f32 = 22.;
146const TYPING_BUBBLE_HEIGHT: f32 = 28.;
147const TYPING_BUBBLE_PADDING: f32 = 12.;
148const TYPING_SIDE_INSET: f32 = 20.;
149const TYPING_BOTTOM_GAP: f32 = 8.;
150pub const TYPING_TAG: &str = "shell/islands/main/typing";
147const TYPING_DOT_SIZE: f32 = 5.;
151const TYPING_DOT_SIZE: f32 = 5.;
148const TYPING_DOT_COUNT: usize = 3;
152const TYPING_DOT_COUNT: usize = 3;
149const TYPING_PULSE_PERIOD: Duration = Duration::from_millis(1200);
153const TYPING_PULSE_PERIOD: Duration = Duration::from_millis(1200);
@@ -862,7 +866,10 @@ impl ConversationView {
862 }
866 }
863 }
867 }
864
868
865 fn render_typing_line(&self, cx: &App) -> impl IntoElement {
869 fn render_typing_line(&self, cx: &App) -> Option<AnyElement> {
870 if self.in_feed() {
871 return None;
872 }
866 let app = self.app.read(cx);
873 let app = self.app.read(cx);
867 let faces = self
874 let faces = self
868 .current
875 .current
@@ -870,18 +877,17 @@ impl ConversationView {
870 .filter(|_| !self.draft_active)
877 .filter(|_| !self.draft_active)
871 .map(|current| app.typing.faces(current.selection.conversation_id()))
878 .map(|current| app.typing.faces(current.selection.conversation_id()))
872 .unwrap_or_default();
879 .unwrap_or_default();
880 if faces.is_empty() {
881 return None;
882 }
873 let tooltip_text = typing_tooltip(
883 let tooltip_text = typing_tooltip(
874 &faces
884 &faces
875 .iter()
885 .iter()
876 .map(|face| face.name.clone())
886 .map(|face| face.name.clone())
877 .collect::<Vec<_>>(),
887 .collect::<Vec<_>>(),
878 );
888 );
879 let flat = matches!(
880 self.current.as_ref().map(|current| &current.mode),
881 Some(ViewMode::Flat)
882 );
883 let faces_element = match faces.as_slice() {
889 let faces_element = match faces.as_slice() {
884 [face] if flat => person_avatar(
890 [face] => person_avatar(
885 &app.directory,
891 &app.directory,
886 face.user_id.as_deref(),
892 face.user_id.as_deref(),
887 &face.name,
893 &face.name,
@@ -889,27 +895,33 @@ impl ConversationView {
889 ),
895 ),
890 _ => member_stack(&app.directory, &faces, faces.len(), true).into_any_element(),
896 _ => member_stack(&app.directory, &faces, faces.len(), true).into_any_element(),
891 };
897 };
892 h_flex()
898 Some(
893 .h(px(if flat {
899 h_flex()
894 AVATAR_SIZE + 4.
900 .debug_selector(|| TYPING_TAG.into())
895 } else {
901 .h(px(TYPING_BUBBLE_HEIGHT))
896 TYPING_LINE_HEIGHT
902 .px(px(TYPING_SIDE_INSET))
897 }))
903 .gap(px(AVATAR_GAP))
898 .flex_none()
904 .items_center()
899 .px(px(20.))
905 .child(
900 .gap(px(if flat { AVATAR_GAP } else { 6. }))
901 .items_center()
902 .when(!faces.is_empty(), |line| {
903 line.child(
904 div()
906 div()
905 .id("typing-faces")
907 .id("typing-faces")
908 .flex_none()
906 .tooltip(move |window, cx| {
909 .tooltip(move |window, cx| {
907 Tooltip::new(tooltip_text.clone()).build(window, cx)
910 Tooltip::new(tooltip_text.clone()).build(window, cx)
908 })
911 })
909 .child(faces_element),
912 .child(faces_element),
910 )
913 )
911 .child(typing_dots())
914 .child(
912 })
915 h_flex()
916 .h_full()
917 .px(px(TYPING_BUBBLE_PADDING))
918 .items_center()
919 .rounded_full()
920 .bg(theme::surface_raised())
921 .child(typing_dots()),
922 )
923 .into_any_element(),
924 )
913 }
925 }
914
926
915 fn open(&mut self, selection: Selection, window: &mut Window, cx: &mut Context<Self>) {
927 fn open(&mut self, selection: Selection, window: &mut Window, cx: &mut Context<Self>) {
@@ -3981,6 +3993,15 @@ impl Render for ConversationView {
3981 let timeline_top_inset = pin_banner_inset(pin_banner.is_some());
3993 let timeline_top_inset = pin_banner_inset(pin_banner.is_some());
3982 let comfy = self.app.read(cx).account_chat_settings().message_density
3994 let comfy = self.app.read(cx).account_chat_settings().message_density
3983 != teams_core::MessageDensity::Compact;
3995 != teams_core::MessageDensity::Compact;
3996 let typing_line = self.render_typing_line(cx);
3997 let typing_offset = {
3998 let scroller = self.scroller.read(cx);
3999 let last_row = scroller.item_count().checked_sub(1);
4000 typing_bottom_offset(
4001 self.timeline_bounds.get(),
4002 last_row.and_then(|index| scroller.item_bounds(index)),
4003 )
4004 };
3984 let scroller = MessageScroller::new(
4005 let scroller = MessageScroller::new(
3985 "messages",
4006 "messages",
3986 self.scroller.clone(),
4007 self.scroller.clone(),
@@ -4097,7 +4118,11 @@ impl Render for ConversationView {
4097 view.update(cx, |this, cx| this.leave_detached(cx)).ok();
4118 view.update(cx, |this, cx| this.leave_detached(cx)).ok();
4098 })
4119 })
4099 })
4120 })
4100 .with_bottom_fade(background)
4121 .when(typing_line.is_some(), |scroller| {
4122 scroller.with_list_style(
4123 StyleRefinement::default().pb(px(TYPING_BUBBLE_HEIGHT + 2. * TYPING_BOTTOM_GAP)),
4124 )
4125 })
4101 .with_top_inset(timeline_top_inset);
4126 .with_top_inset(timeline_top_inset);
4102
4127
4103 root = match self.current.as_ref().filter(|_| !drafting) {
4128 root = match self.current.as_ref().filter(|_| !drafting) {
@@ -4195,6 +4220,14 @@ impl Render for ConversationView {
4195 .child(record_bounds(&self.timeline_bounds, timeline_top_inset))
4220 .child(record_bounds(&self.timeline_bounds, timeline_top_inset))
4196 .on_scroll_wheel(cx.listener(|this, _, _, cx| this.close_reaction_details(cx)))
4221 .on_scroll_wheel(cx.listener(|this, _, _, cx| this.close_reaction_details(cx)))
4197 .child(body)
4222 .child(body)
4223 .children(typing_line.map(|line| {
4224 div()
4225 .absolute()
4226 .left_0()
4227 .right_0()
4228 .bottom(px(typing_offset))
4229 .child(runway(line, comfy))
4230 }))
4198 .when(feed_scrolled, |timeline| {
4231 .when(feed_scrolled, |timeline| {
4199 timeline.child(
4232 timeline.child(
4200 edge_divider(FEED_EDGE_TAG)
4233 edge_divider(FEED_EDGE_TAG)
@@ -4216,7 +4249,6 @@ impl Render for ConversationView {
4216 None => column.child(runway(
4249 None => column.child(runway(
4217 v_flex()
4250 v_flex()
4218 .w_full()
4251 .w_full()
4219 .child(self.render_typing_line(cx))
4220 .children(self.render_proposal_card(cx))
4252 .children(self.render_proposal_card(cx))
4221 .child(self.composer.clone()),
4253 .child(self.composer.clone()),
4222 comfy,
4254 comfy,
@@ -4275,6 +4307,17 @@ impl Render for ConversationView {
4275 }
4307 }
4276}
4308}
4277
4309
4310/// Right under the last row like one more message; once that row scrolls below the view it sticks above the composer.
4311fn typing_bottom_offset(timeline: Option<Bounds<Pixels>>, last_row: Option<Bounds<Pixels>>) -> f32 {
4312 let (Some(timeline), Some(last_row)) = (timeline, last_row) else {
4313 return TYPING_BOTTOM_GAP;
4314 };
4315 let under_last_row = f32::from(timeline.bottom() - last_row.bottom())
4316 - TYPING_BOTTOM_GAP
4317 - TYPING_BUBBLE_HEIGHT;
4318 under_last_row.max(TYPING_BOTTOM_GAP)
4319}
4320
4278fn typing_dots() -> impl IntoElement {
4321fn typing_dots() -> impl IntoElement {
4279 h_flex()
4322 h_flex()
4280 .gap(px(3.))
4323 .gap(px(3.))
@@ -4370,7 +4413,7 @@ fn runway(content: impl IntoElement, comfy: bool) -> AnyElement {
4370mod tests {
4413mod tests {
4371 use std::sync::Arc;
4414 use std::sync::Arc;
4372
4415
4373 use super::{DropTarget, drop_overlay_text};
4416 use super::{DropTarget, drop_overlay_text, typing_bottom_offset};
4374
4417
4375 use gpui_kit::test::TestWindowExt as _;
4418 use gpui_kit::test::TestWindowExt as _;
4376 use gpui_kit::{AppContext as _, TestAppContext, WindowOptions};
4419 use gpui_kit::{AppContext as _, TestAppContext, WindowOptions};
@@ -4504,4 +4547,14 @@ mod tests {
4504 assert_eq!(state.selection, Some(crate::demo::first_selection()));
4547 assert_eq!(state.selection, Some(crate::demo::first_selection()));
4505 });
4548 });
4506 }
4549 }
4550
4551 #[test]
4552 fn the_typing_bubble_follows_the_last_row_and_sticks_above_the_composer() {
4553 use gpui_kit::{Bounds, point, px, size};
4554 let timeline = Bounds::new(point(px(0.), px(100.)), size(px(800.), px(600.)));
4555 let row_ending_at = |bottom: f32| Some(Bounds::new(point(px(0.), px(bottom - 50.)), size(px(800.), px(50.))));
4556 assert_eq!(typing_bottom_offset(Some(timeline), row_ending_at(400.)), 264.);
4557 assert_eq!(typing_bottom_offset(Some(timeline), row_ending_at(900.)), 8.);
4558 assert_eq!(typing_bottom_offset(Some(timeline), None), 8.);
4559 }
4507}
4560}
vendor/gpui-component/PATCHES.md +1 −0
@@ -15,3 +15,4 @@ Upstream: crates.io `gpui-component 0.7.1`. Wired in via `[patch.crates-io]` in
15 15 | `src/button/button.rs` | no managed tooltip while the button is held `open` by its popover or dropdown menu | same, for Button triggers |
16 16 | `src/tooltip.rs` | managed tooltip requests carry a liveness token from the trigger's element state (`while_alive`); `TOOLTIP_DEBUG_SELECTOR` on `Tooltip` | a tooltip closes when its trigger is no longer rendered (e.g. "Jump to newest" after the button vanished); tests find tooltips |
17 17 | `src/message_scroller.rs` | `wheel_mask(bool)` builder, default on; off skips the `ScrollableMask` child | the mask scrolls the list in the capture phase, so an editor inside a row (channel thread reply) never got the wheel |
18 | `src/message_scroller.rs` | `MessageScrollerState::item_bounds(index)` | the typing bubble sits right under the last row and sticks above the composer once that row scrolls away |
@@ -15,3 +15,4 @@ Upstream: crates.io `gpui-component 0.7.1`. Wired in via `[patch.crates-io]` in
15| `src/button/button.rs` | no managed tooltip while the button is held `open` by its popover or dropdown menu | same, for Button triggers |
15| `src/button/button.rs` | no managed tooltip while the button is held `open` by its popover or dropdown menu | same, for Button triggers |
16| `src/tooltip.rs` | managed tooltip requests carry a liveness token from the trigger's element state (`while_alive`); `TOOLTIP_DEBUG_SELECTOR` on `Tooltip` | a tooltip closes when its trigger is no longer rendered (e.g. "Jump to newest" after the button vanished); tests find tooltips |
16| `src/tooltip.rs` | managed tooltip requests carry a liveness token from the trigger's element state (`while_alive`); `TOOLTIP_DEBUG_SELECTOR` on `Tooltip` | a tooltip closes when its trigger is no longer rendered (e.g. "Jump to newest" after the button vanished); tests find tooltips |
17| `src/message_scroller.rs` | `wheel_mask(bool)` builder, default on; off skips the `ScrollableMask` child | the mask scrolls the list in the capture phase, so an editor inside a row (channel thread reply) never got the wheel |
17| `src/message_scroller.rs` | `wheel_mask(bool)` builder, default on; off skips the `ScrollableMask` child | the mask scrolls the list in the capture phase, so an editor inside a row (channel thread reply) never got the wheel |
18| `src/message_scroller.rs` | `MessageScrollerState::item_bounds(index)` | the typing bubble sits right under the last row and sticks above the composer once that row scrolls away |
vendor/gpui-component/src/message_scroller.rs +5 −0
@@ -78,6 +78,11 @@ impl MessageScrollerState {
78 78 self.list_state.logical_scroll_top().item_ix
79 79 }
80 80
81 /// Window bounds of a row from the last layout, `None` when it was not rendered.
82 pub fn item_bounds(&self, index: usize) -> Option<gpui::Bounds<gpui::Pixels>> {
83 self.list_state.bounds_for_item(index)
84 }
85
81 86 /// Return whether the list is actively following its tail.
82 87 pub fn is_following_tail(&self) -> bool {
83 88 self.list_state.is_following_tail()
@@ -78,6 +78,11 @@ impl MessageScrollerState {
78 self.list_state.logical_scroll_top().item_ix
78 self.list_state.logical_scroll_top().item_ix
79 }
79 }
80
80
81 /// Window bounds of a row from the last layout, `None` when it was not rendered.
82 pub fn item_bounds(&self, index: usize) -> Option<gpui::Bounds<gpui::Pixels>> {
83 self.list_state.bounds_for_item(index)
84 }
85
81 /// Return whether the list is actively following its tail.
86 /// Return whether the list is actively following its tail.
82 pub fn is_following_tail(&self) -> bool {
87 pub fn is_following_tail(&self) -> bool {
83 self.list_state.is_following_tail()
88 self.list_state.is_following_tail()