fix(chat): typing bubble keeps its place when a sent message lands
- A row added or replaced since the last frame has no bounds yet; the bubble now keeps its previous offset instead of dropping to the composer gap for a frame - layout_guard test: the bubble does not move back and forth when a message arrives while someone types Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -198,7 +198,7 @@ mod frames {
198
198
};
199
199
use crate::views::conversation::{
200
200
FEED_EDGE_TAG, FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG,
201
FORWARD_FOOTER_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG,
201
FORWARD_FOOTER_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG, TYPING_TAG,
202
202
};
203
203
use crate::views::find_panel::{
204
204
FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,
@@ -1364,6 +1364,83 @@ mod frames {
1364
1364
}
1365
1365
}
1366
1366
1367
#[gpui_kit::test]
1368
fn the_typing_bubble_stays_put_when_an_own_message_arrives(cx: &mut TestAppContext) {
1369
let (handle, app) = mount(cx);
1370
let mut visual = VisualTestContext::from_window(handle, cx);
1371
visual.simulate_resize(size(px(1280.), px(520.)));
1372
visual.update(|_, cx| {
1373
app.update(cx, |state, cx| {
1374
state.select(Selection::Chat(REACTION_CHAT.to_owned()), cx)
1375
})
1376
});
1377
collect(&mut visual, Some(TYPING_TAG));
1378
collect(&mut visual, None);
1379
let resting = visual
1380
.debug_bounds(TYPING_TAG)
1381
.expect("typing bubble")
1382
.bottom();
1383
visual.update(|_, cx| {
1384
app.update(cx, |state, cx| {
1385
let record = store::MessageRecord {
1386
conversation_id: REACTION_CHAT.to_owned(),
1387
message_id: "guard-own".to_owned(),
1388
sender_id: Some(demo::DEMO_USER_ID.to_owned()),
1389
sender_name: Some("Me".to_owned()),
1390
created_at: chrono::Utc::now().max(demo::at(0, 10, 48)),
1391
body_html: "<p>Sent while Mara types</p>".to_owned(),
1392
links_json: "[]".to_owned(),
1393
attachments_json: "[]".to_owned(),
1394
reactions_json: "[]".to_owned(),
1395
mentions_json: "[]".to_owned(),
1396
..Default::default()
1397
};
1398
state
1399
.store
1400
.upsert_messages(&[record])
1401
.expect("store message");
1402
state.typing.start(
1403
REACTION_CHAT,
1404
demo::MARA_ID,
1405
"Mara Lindqvist",
1406
std::time::Instant::now(),
1407
chrono::Utc::now() + chrono::Duration::days(1),
1408
);
1409
state.apply(
1410
crate::backend::BackendEvent::Core(teams_core::CoreEvent::MessagesChanged {
1411
conversation_id: REACTION_CHAT.to_owned(),
1412
}),
1413
cx,
1414
);
1415
})
1416
});
1417
let mut bottoms = Vec::new();
1418
for _ in 0..12 {
1419
visual.executor().advance_clock(Duration::from_millis(16));
1420
visual.run_until_parked();
1421
visual.update(|window, cx| window.render_frame(cx));
1422
bottoms.push(
1423
visual
1424
.debug_bounds(TYPING_TAG)
1425
.map(|bounds| f32::from(bounds.bottom())),
1426
);
1427
}
1428
let positions: Vec<f32> = bottoms
1429
.iter()
1430
.map(|bottom| bottom.expect("typing bubble"))
1431
.collect();
1432
let steps: Vec<f32> = positions
1433
.windows(2)
1434
.map(|pair| pair[1] - pair[0])
1435
.filter(|step| step.abs() > 0.5)
1436
.collect();
1437
let reversals = steps
1438
.windows(2)
1439
.filter(|pair| pair[0].signum() != pair[1].signum())
1440
.count();
1441
assert_eq!(reversals, 0, "resting {resting:?}, frames {positions:?}");
1442
}
1443
1367
1444
#[gpui_kit::test]
1368
1445
fn a_new_message_never_opens_a_gap_between_the_rows_above(cx: &mut TestAppContext) {
1369
1446
const GAP_CHAT: &str = "demo-chat-priya";
@@ -198,7 +198,7 @@ mod frames {198
};198
};199
use crate::views::conversation::{199
use crate::views::conversation::{200
FEED_EDGE_TAG, FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG,200
FEED_EDGE_TAG, FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG,201
FORWARD_FOOTER_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG,201
FORWARD_FOOTER_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG, TYPING_TAG,202
};202
};203
use crate::views::find_panel::{203
use crate::views::find_panel::{204
FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,204
FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,@@ -1364,6 +1364,83 @@ mod frames {1364
}1364
}1365
}1365
}1366
1366
1367
#[gpui_kit::test]1368
fn the_typing_bubble_stays_put_when_an_own_message_arrives(cx: &mut TestAppContext) {1369
let (handle, app) = mount(cx);1370
let mut visual = VisualTestContext::from_window(handle, cx);1371
visual.simulate_resize(size(px(1280.), px(520.)));1372
visual.update(|_, cx| {1373
app.update(cx, |state, cx| {1374
state.select(Selection::Chat(REACTION_CHAT.to_owned()), cx)1375
})1376
});1377
collect(&mut visual, Some(TYPING_TAG));1378
collect(&mut visual, None);1379
let resting = visual1380
.debug_bounds(TYPING_TAG)1381
.expect("typing bubble")1382
.bottom();1383
visual.update(|_, cx| {1384
app.update(cx, |state, cx| {1385
let record = store::MessageRecord {1386
conversation_id: REACTION_CHAT.to_owned(),1387
message_id: "guard-own".to_owned(),1388
sender_id: Some(demo::DEMO_USER_ID.to_owned()),1389
sender_name: Some("Me".to_owned()),1390
created_at: chrono::Utc::now().max(demo::at(0, 10, 48)),1391
body_html: "<p>Sent while Mara types</p>".to_owned(),1392
links_json: "[]".to_owned(),1393
attachments_json: "[]".to_owned(),1394
reactions_json: "[]".to_owned(),1395
mentions_json: "[]".to_owned(),1396
..Default::default()1397
};1398
state1399
.store1400
.upsert_messages(&[record])1401
.expect("store message");1402
state.typing.start(1403
REACTION_CHAT,1404
demo::MARA_ID,1405
"Mara Lindqvist",1406
std::time::Instant::now(),1407
chrono::Utc::now() + chrono::Duration::days(1),1408
);1409
state.apply(1410
crate::backend::BackendEvent::Core(teams_core::CoreEvent::MessagesChanged {1411
conversation_id: REACTION_CHAT.to_owned(),1412
}),1413
cx,1414
);1415
})1416
});1417
let mut bottoms = Vec::new();1418
for _ in 0..12 {1419
visual.executor().advance_clock(Duration::from_millis(16));1420
visual.run_until_parked();1421
visual.update(|window, cx| window.render_frame(cx));1422
bottoms.push(1423
visual1424
.debug_bounds(TYPING_TAG)1425
.map(|bounds| f32::from(bounds.bottom())),1426
);1427
}1428
let positions: Vec<f32> = bottoms1429
.iter()1430
.map(|bottom| bottom.expect("typing bubble"))1431
.collect();1432
let steps: Vec<f32> = positions1433
.windows(2)1434
.map(|pair| pair[1] - pair[0])1435
.filter(|step| step.abs() > 0.5)1436
.collect();1437
let reversals = steps1438
.windows(2)1439
.filter(|pair| pair[0].signum() != pair[1].signum())1440
.count();1441
assert_eq!(reversals, 0, "resting {resting:?}, frames {positions:?}");1442
}1443
1367
#[gpui_kit::test]1444
#[gpui_kit::test]1368
fn a_new_message_never_opens_a_gap_between_the_rows_above(cx: &mut TestAppContext) {1445
fn a_new_message_never_opens_a_gap_between_the_rows_above(cx: &mut TestAppContext) {1369
const GAP_CHAT: &str = "demo-chat-priya";1446
const GAP_CHAT: &str = "demo-chat-priya";@@ -280,6 +280,7 @@ pub struct ConversationView {
280
280
context_menu: Option<OpenContextMenu>,
281
281
context_serial: u64,
282
282
timeline_bounds: TimelineBounds,
283
typing_offset: Cell<f32>,
283
284
header_width: Rc<Cell<f32>>,
284
285
toolbar_pinned: Option<String>,
285
286
toolbar_suppressed: Option<String>,
@@ -762,6 +763,7 @@ impl ConversationView {
762
763
context_menu: None,
763
764
context_serial: 0,
764
765
timeline_bounds: TimelineBounds::default(),
766
typing_offset: Cell::new(TYPING_BOTTOM_GAP),
765
767
header_width: Rc::default(),
766
768
toolbar_pinned: None,
767
769
toolbar_suppressed: None,
@@ -4347,10 +4349,13 @@ impl Render for ConversationView {
4347
4349
let typing_offset = {
4348
4350
let scroller = self.scroller.read(cx);
4349
4351
let last_row = scroller.item_count().checked_sub(1);
4350
typing_bottom_offset(
4352
let offset = typing_bottom_offset(
4351
4353
self.timeline_bounds.get(),
4352
4354
last_row.and_then(|index| scroller.item_bounds(index)),
4353
)
4355
self.typing_offset.get(),
4356
);
4357
self.typing_offset.set(offset);
4358
offset
4354
4359
};
4355
4360
let scroller = MessageScroller::new(
4356
4361
"messages",
@@ -4669,9 +4674,14 @@ impl Render for ConversationView {
4669
4674
}
4670
4675
4671
4676
/// Right under the last row like one more message; once that row scrolls below the view it sticks above the composer.
4672
fn typing_bottom_offset(timeline: Option<Bounds<Pixels>>, last_row: Option<Bounds<Pixels>>) -> f32 {
4677
/// A row added or replaced since the last frame has no bounds yet, so the bubble keeps its previous place.
4678
fn typing_bottom_offset(
4679
timeline: Option<Bounds<Pixels>>,
4680
last_row: Option<Bounds<Pixels>>,
4681
previous: f32,
4682
) -> f32 {
4673
4683
let (Some(timeline), Some(last_row)) = (timeline, last_row) else {
4674
return TYPING_BOTTOM_GAP;
4684
return previous;
4675
4685
};
4676
4686
let under_last_row =
4677
4687
f32::from(timeline.bottom() - last_row.bottom()) - TYPING_TOP_GAP - TYPING_BUBBLE_HEIGHT;
@@ -4965,14 +4975,14 @@ mod tests {
4965
4975
))
4966
4976
};
4967
4977
assert_eq!(
4968
typing_bottom_offset(Some(timeline), row_ending_at(400.)),
4978
typing_bottom_offset(Some(timeline), row_ending_at(400.), 8.),
4969
4979
256.
4970
4980
);
4971
4981
assert_eq!(
4972
typing_bottom_offset(Some(timeline), row_ending_at(900.)),
4982
typing_bottom_offset(Some(timeline), row_ending_at(900.), 8.),
4973
4983
8.
4974
4984
);
4975
assert_eq!(typing_bottom_offset(Some(timeline), None), 8.);
4985
assert_eq!(typing_bottom_offset(Some(timeline), None, 13.), 13.);
4976
4986
}
4977
4987
4978
4988
#[test]
@@ -280,6 +280,7 @@ pub struct ConversationView {280
context_menu: Option<OpenContextMenu>,280
context_menu: Option<OpenContextMenu>,281
context_serial: u64,281
context_serial: u64,282
timeline_bounds: TimelineBounds,282
timeline_bounds: TimelineBounds,283
typing_offset: Cell<f32>,283
header_width: Rc<Cell<f32>>,284
header_width: Rc<Cell<f32>>,284
toolbar_pinned: Option<String>,285
toolbar_pinned: Option<String>,285
toolbar_suppressed: Option<String>,286
toolbar_suppressed: Option<String>,@@ -762,6 +763,7 @@ impl ConversationView {762
context_menu: None,763
context_menu: None,763
context_serial: 0,764
context_serial: 0,764
timeline_bounds: TimelineBounds::default(),765
timeline_bounds: TimelineBounds::default(),766
typing_offset: Cell::new(TYPING_BOTTOM_GAP),765
header_width: Rc::default(),767
header_width: Rc::default(),766
toolbar_pinned: None,768
toolbar_pinned: None,767
toolbar_suppressed: None,769
toolbar_suppressed: None,@@ -4347,10 +4349,13 @@ impl Render for ConversationView {4347
let typing_offset = {4349
let typing_offset = {4348
let scroller = self.scroller.read(cx);4350
let scroller = self.scroller.read(cx);4349
let last_row = scroller.item_count().checked_sub(1);4351
let last_row = scroller.item_count().checked_sub(1);4350
typing_bottom_offset(4352
let offset = typing_bottom_offset(4351
self.timeline_bounds.get(),4353
self.timeline_bounds.get(),4352
last_row.and_then(|index| scroller.item_bounds(index)),4354
last_row.and_then(|index| scroller.item_bounds(index)),4353
)4355
self.typing_offset.get(),4356
);4357
self.typing_offset.set(offset);4358
offset4354
};4359
};4355
let scroller = MessageScroller::new(4360
let scroller = MessageScroller::new(4356
"messages",4361
"messages",@@ -4669,9 +4674,14 @@ impl Render for ConversationView {4669
}4674
}4670
4675
4671
/// Right under the last row like one more message; once that row scrolls below the view it sticks above the composer.4676
/// Right under the last row like one more message; once that row scrolls below the view it sticks above the composer.4672
fn typing_bottom_offset(timeline: Option<Bounds<Pixels>>, last_row: Option<Bounds<Pixels>>) -> f32 {4677
/// A row added or replaced since the last frame has no bounds yet, so the bubble keeps its previous place.4678
fn typing_bottom_offset(4679
timeline: Option<Bounds<Pixels>>,4680
last_row: Option<Bounds<Pixels>>,4681
previous: f32,4682
) -> f32 {4673
let (Some(timeline), Some(last_row)) = (timeline, last_row) else {4683
let (Some(timeline), Some(last_row)) = (timeline, last_row) else {4674
return TYPING_BOTTOM_GAP;4684
return previous;4675
};4685
};4676
let under_last_row =4686
let under_last_row =4677
f32::from(timeline.bottom() - last_row.bottom()) - TYPING_TOP_GAP - TYPING_BUBBLE_HEIGHT;4687
f32::from(timeline.bottom() - last_row.bottom()) - TYPING_TOP_GAP - TYPING_BUBBLE_HEIGHT;@@ -4965,14 +4975,14 @@ mod tests {4965
))4975
))4966
};4976
};4967
assert_eq!(4977
assert_eq!(4968
typing_bottom_offset(Some(timeline), row_ending_at(400.)),4978
typing_bottom_offset(Some(timeline), row_ending_at(400.), 8.),4969
256.4979
256.4970
);4980
);4971
assert_eq!(4981
assert_eq!(4972
typing_bottom_offset(Some(timeline), row_ending_at(900.)),4982
typing_bottom_offset(Some(timeline), row_ending_at(900.), 8.),4973
8.4983
8.4974
);4984
);4975
assert_eq!(typing_bottom_offset(Some(timeline), None), 8.);4985
assert_eq!(typing_bottom_offset(Some(timeline), None, 13.), 13.);4976
}4986
}4977
4987
4978
#[test]4988
#[test]