BlueGit

ict rusty-teams

fix(chat): time of a short message with reactions stays in its bubble

- a negative right margin on the time dropped the reaction line from the bubble's max-content width, so the bubble sized to the text alone
- the time now moves into the padding with a relative offset
- layout_guard test: short own message with a reaction keeps its time 8 px inside the bubble

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-20 · 11 days ago

Hash
9dc4ec73461859924bd820055bfb507b743f9184
Parent
3948af09
2 files changed +95 −11
crates/app/src/layout_guard.rs +57 −1
@@ -206,7 +206,7 @@ mod frames {
206 206 use crate::views::forward_dialog::{FORWARD_CARD_TAG, FORWARD_PREVIEW_TAG};
207 207 use crate::views::group_name::{GROUP_NAME_BUTTON, GROUP_NAME_FORM};
208 208 use crate::views::message_row::{
209 BUBBLE_TAGS, IMPORTANCE_LABEL_TAG, bubble_padding_y, select_box_selector,
209 BUBBLE_META_TAGS, BUBBLE_TAGS, IMPORTANCE_LABEL_TAG, bubble_padding_y, select_box_selector,
210 210 };
211 211 use crate::views::pin_banner::{BANNER_INSET, PIN_BANNER_TAG};
212 212 use crate::views::post_card::{
@@ -1441,6 +1441,62 @@ mod frames {
1441 1441 assert_eq!(reversals, 0, "resting {resting:?}, frames {positions:?}");
1442 1442 }
1443 1443
1444 #[gpui_kit::test]
1445 fn the_time_of_a_short_own_message_with_a_reaction_stays_in_its_bubble(
1446 cx: &mut TestAppContext,
1447 ) {
1448 const SHORT_CHAT: &str = "demo-chat-priya";
1449 let (handle, app) = mount(cx);
1450 let mut visual = VisualTestContext::from_window(handle, cx);
1451 visual.simulate_resize(size(px(1280.), px(800.)));
1452 visual.update(|_, cx| {
1453 app.update(cx, |state, cx| {
1454 let reactions = vec![teams_core::ReactionInfo {
1455 reaction_type: "like".to_owned(),
1456 user_id: Some(demo::MARA_ID.to_owned()),
1457 user_name: Some("Mara Lindqvist".to_owned()),
1458 created_at: Some(chrono::Utc::now()),
1459 }];
1460 let record = store::MessageRecord {
1461 conversation_id: SHORT_CHAT.to_owned(),
1462 message_id: "guard-short".to_owned(),
1463 sender_id: Some(demo::DEMO_USER_ID.to_owned()),
1464 sender_name: Some("Me".to_owned()),
1465 created_at: chrono::Utc::now().max(demo::at(0, 10, 48)),
1466 body_html: "<p>danke</p>".to_owned(),
1467 links_json: "[]".to_owned(),
1468 attachments_json: "[]".to_owned(),
1469 reactions_json: serde_json::to_string(&reactions).expect("reactions"),
1470 mentions_json: "[]".to_owned(),
1471 ..Default::default()
1472 };
1473 state
1474 .store
1475 .upsert_messages(&[record])
1476 .expect("store message");
1477 state.select(Selection::Chat(SHORT_CHAT.to_owned()), cx)
1478 })
1479 });
1480 collect(&mut visual, Some(TIMELINE_TAG));
1481 collect(&mut visual, None);
1482 let pairs: Vec<(Bounds<Pixels>, Bounds<Pixels>)> = BUBBLE_TAGS
1483 .iter()
1484 .zip(BUBBLE_META_TAGS)
1485 .filter_map(|(bubble, meta)| {
1486 Some((visual.debug_bounds(bubble)?, visual.debug_bounds(meta)?))
1487 })
1488 .collect();
1489 let (bubble, meta) = pairs
1490 .iter()
1491 .max_by(|left, right| f32::from(left.0.top()).total_cmp(&f32::from(right.0.top())))
1492 .expect("the newest bubble and its time");
1493 assert_eq!(
1494 f32::from(bubble.right() - meta.right()),
1495 8.,
1496 "time {meta:?} is not 8 px inside its bubble {bubble:?}"
1497 );
1498 }
1499
1444 1500 #[gpui_kit::test]
1445 1501 fn a_new_message_never_opens_a_gap_between_the_rows_above(cx: &mut TestAppContext) {
1446 1502 const GAP_CHAT: &str = "demo-chat-priya";
@@ -206,7 +206,7 @@ mod frames {
206 use crate::views::forward_dialog::{FORWARD_CARD_TAG, FORWARD_PREVIEW_TAG};
206 use crate::views::forward_dialog::{FORWARD_CARD_TAG, FORWARD_PREVIEW_TAG};
207 use crate::views::group_name::{GROUP_NAME_BUTTON, GROUP_NAME_FORM};
207 use crate::views::group_name::{GROUP_NAME_BUTTON, GROUP_NAME_FORM};
208 use crate::views::message_row::{
208 use crate::views::message_row::{
209 BUBBLE_TAGS, IMPORTANCE_LABEL_TAG, bubble_padding_y, select_box_selector,
209 BUBBLE_META_TAGS, BUBBLE_TAGS, IMPORTANCE_LABEL_TAG, bubble_padding_y, select_box_selector,
210 };
210 };
211 use crate::views::pin_banner::{BANNER_INSET, PIN_BANNER_TAG};
211 use crate::views::pin_banner::{BANNER_INSET, PIN_BANNER_TAG};
212 use crate::views::post_card::{
212 use crate::views::post_card::{
@@ -1441,6 +1441,62 @@ mod frames {
1441 assert_eq!(reversals, 0, "resting {resting:?}, frames {positions:?}");
1441 assert_eq!(reversals, 0, "resting {resting:?}, frames {positions:?}");
1442 }
1442 }
1443
1443
1444 #[gpui_kit::test]
1445 fn the_time_of_a_short_own_message_with_a_reaction_stays_in_its_bubble(
1446 cx: &mut TestAppContext,
1447 ) {
1448 const SHORT_CHAT: &str = "demo-chat-priya";
1449 let (handle, app) = mount(cx);
1450 let mut visual = VisualTestContext::from_window(handle, cx);
1451 visual.simulate_resize(size(px(1280.), px(800.)));
1452 visual.update(|_, cx| {
1453 app.update(cx, |state, cx| {
1454 let reactions = vec![teams_core::ReactionInfo {
1455 reaction_type: "like".to_owned(),
1456 user_id: Some(demo::MARA_ID.to_owned()),
1457 user_name: Some("Mara Lindqvist".to_owned()),
1458 created_at: Some(chrono::Utc::now()),
1459 }];
1460 let record = store::MessageRecord {
1461 conversation_id: SHORT_CHAT.to_owned(),
1462 message_id: "guard-short".to_owned(),
1463 sender_id: Some(demo::DEMO_USER_ID.to_owned()),
1464 sender_name: Some("Me".to_owned()),
1465 created_at: chrono::Utc::now().max(demo::at(0, 10, 48)),
1466 body_html: "<p>danke</p>".to_owned(),
1467 links_json: "[]".to_owned(),
1468 attachments_json: "[]".to_owned(),
1469 reactions_json: serde_json::to_string(&reactions).expect("reactions"),
1470 mentions_json: "[]".to_owned(),
1471 ..Default::default()
1472 };
1473 state
1474 .store
1475 .upsert_messages(&[record])
1476 .expect("store message");
1477 state.select(Selection::Chat(SHORT_CHAT.to_owned()), cx)
1478 })
1479 });
1480 collect(&mut visual, Some(TIMELINE_TAG));
1481 collect(&mut visual, None);
1482 let pairs: Vec<(Bounds<Pixels>, Bounds<Pixels>)> = BUBBLE_TAGS
1483 .iter()
1484 .zip(BUBBLE_META_TAGS)
1485 .filter_map(|(bubble, meta)| {
1486 Some((visual.debug_bounds(bubble)?, visual.debug_bounds(meta)?))
1487 })
1488 .collect();
1489 let (bubble, meta) = pairs
1490 .iter()
1491 .max_by(|left, right| f32::from(left.0.top()).total_cmp(&f32::from(right.0.top())))
1492 .expect("the newest bubble and its time");
1493 assert_eq!(
1494 f32::from(bubble.right() - meta.right()),
1495 8.,
1496 "time {meta:?} is not 8 px inside its bubble {bubble:?}"
1497 );
1498 }
1499
1444 #[gpui_kit::test]
1500 #[gpui_kit::test]
1445 fn a_new_message_never_opens_a_gap_between_the_rows_above(cx: &mut TestAppContext) {
1501 fn a_new_message_never_opens_a_gap_between_the_rows_above(cx: &mut TestAppContext) {
1446 const GAP_CHAT: &str = "demo-chat-priya";
1502 const GAP_CHAT: &str = "demo-chat-priya";
crates/app/src/views/message_row.rs +38 −10
@@ -37,6 +37,20 @@ use app_ui_kit::layout::{COMFY_RUNWAY_WIDTH, ROW_PADDING};
37 37 pub type RowAction = Option<Box<dyn Fn(&mut App)>>;
38 38 pub type SharedRowAction = Option<std::rc::Rc<dyn Fn(&mut App)>>;
39 39
40 pub const BUBBLE_META_TAGS: [&str; 12] = [
41 "message-bubble/0/meta",
42 "message-bubble/1/meta",
43 "message-bubble/2/meta",
44 "message-bubble/3/meta",
45 "message-bubble/4/meta",
46 "message-bubble/5/meta",
47 "message-bubble/6/meta",
48 "message-bubble/7/meta",
49 "message-bubble/8/meta",
50 "message-bubble/9/meta",
51 "message-bubble/10/meta",
52 "message-bubble/11/meta",
53 ];
40 54 pub const BUBBLE_TAGS: [&str; 12] = [
41 55 "message-bubble/0",
42 56 "message-bubble/1",
@@ -371,21 +385,21 @@ fn bubble(
371 385 } else {
372 386 pills.flex_auto()
373 387 })
374 .child(
388 .child(shifted_right(
375 389 h_flex()
376 390 .flex_none()
377 391 .mb(px(META_BOTTOM_INSET - bubble_padding_y(extras.compact)))
378 .mr(px(meta_right_shift(jumbo.is_some())))
379 .child(bubble_meta(row, own, saved)),
380 ),
392 .child(bubble_meta(row, index, own, saved)),
393 jumbo.is_some(),
394 )),
381 395 );
382 396 } else if !meta_inline {
383 content = content.child(
397 content = content.child(shifted_right(
384 398 h_flex()
385 399 .justify_end()
386 .mr(px(meta_right_shift(jumbo.is_some())))
387 .child(bubble_meta(row, own, saved)),
388 );
400 .child(bubble_meta(row, index, own, saved)),
401 jumbo.is_some(),
402 ));
389 403 }
390 404 element = element.child(content);
391 405 if meta_inline {
@@ -394,7 +408,7 @@ fn bubble(
394 408 .absolute()
395 409 .right(px(META_RIGHT_INSET))
396 410 .bottom(px(META_BOTTOM_INSET))
397 .child(bubble_meta(row, own, saved)),
411 .child(bubble_meta(row, index, own, saved)),
398 412 );
399 413 }
400 414 if let Some(menu) = extras.menu {
@@ -474,13 +488,27 @@ fn meta_right_shift(jumbo: bool) -> f32 {
474 488 }
475 489 }
476 490
477 fn bubble_meta(row: &MessageRow, own: bool, saved: bool) -> Div {
491 /// A negative margin drops the whole row from taffy's max-content width, so the meta moves into the padding by offset.
492 fn shifted_right(meta: Div, jumbo: bool) -> Div {
493 let shift = meta_right_shift(jumbo);
494 if shift < 0. {
495 let into_padding = shift.abs();
496 meta.relative().left(px(into_padding))
497 } else {
498 meta.mr(px(shift))
499 }
500 }
501
502 fn bubble_meta(row: &MessageRow, index: usize, own: bool, saved: bool) -> Div {
478 503 let tint = if own {
479 504 theme::own_meta()
480 505 } else {
481 506 theme::text_muted()
482 507 };
483 508 h_flex()
509 .when_some(BUBBLE_META_TAGS.get(index).copied(), |meta, tag| {
510 meta.debug_selector(|| tag.into())
511 })
484 512 .gap(px(4.))
485 513 .items_center()
486 514 .text_size(px(META_SIZE))
@@ -37,6 +37,20 @@ use app_ui_kit::layout::{COMFY_RUNWAY_WIDTH, ROW_PADDING};
37pub type RowAction = Option<Box<dyn Fn(&mut App)>>;
37pub type RowAction = Option<Box<dyn Fn(&mut App)>>;
38pub type SharedRowAction = Option<std::rc::Rc<dyn Fn(&mut App)>>;
38pub type SharedRowAction = Option<std::rc::Rc<dyn Fn(&mut App)>>;
39
39
40pub const BUBBLE_META_TAGS: [&str; 12] = [
41 "message-bubble/0/meta",
42 "message-bubble/1/meta",
43 "message-bubble/2/meta",
44 "message-bubble/3/meta",
45 "message-bubble/4/meta",
46 "message-bubble/5/meta",
47 "message-bubble/6/meta",
48 "message-bubble/7/meta",
49 "message-bubble/8/meta",
50 "message-bubble/9/meta",
51 "message-bubble/10/meta",
52 "message-bubble/11/meta",
53];
40pub const BUBBLE_TAGS: [&str; 12] = [
54pub const BUBBLE_TAGS: [&str; 12] = [
41 "message-bubble/0",
55 "message-bubble/0",
42 "message-bubble/1",
56 "message-bubble/1",
@@ -371,21 +385,21 @@ fn bubble(
371 } else {
385 } else {
372 pills.flex_auto()
386 pills.flex_auto()
373 })
387 })
374 .child(
388 .child(shifted_right(
375 h_flex()
389 h_flex()
376 .flex_none()
390 .flex_none()
377 .mb(px(META_BOTTOM_INSET - bubble_padding_y(extras.compact)))
391 .mb(px(META_BOTTOM_INSET - bubble_padding_y(extras.compact)))
378 .mr(px(meta_right_shift(jumbo.is_some())))
392 .child(bubble_meta(row, index, own, saved)),
379 .child(bubble_meta(row, own, saved)),
393 jumbo.is_some(),
380 ),
394 )),
381 );
395 );
382 } else if !meta_inline {
396 } else if !meta_inline {
383 content = content.child(
397 content = content.child(shifted_right(
384 h_flex()
398 h_flex()
385 .justify_end()
399 .justify_end()
386 .mr(px(meta_right_shift(jumbo.is_some())))
400 .child(bubble_meta(row, index, own, saved)),
387 .child(bubble_meta(row, own, saved)),
401 jumbo.is_some(),
388 );
402 ));
389 }
403 }
390 element = element.child(content);
404 element = element.child(content);
391 if meta_inline {
405 if meta_inline {
@@ -394,7 +408,7 @@ fn bubble(
394 .absolute()
408 .absolute()
395 .right(px(META_RIGHT_INSET))
409 .right(px(META_RIGHT_INSET))
396 .bottom(px(META_BOTTOM_INSET))
410 .bottom(px(META_BOTTOM_INSET))
397 .child(bubble_meta(row, own, saved)),
411 .child(bubble_meta(row, index, own, saved)),
398 );
412 );
399 }
413 }
400 if let Some(menu) = extras.menu {
414 if let Some(menu) = extras.menu {
@@ -474,13 +488,27 @@ fn meta_right_shift(jumbo: bool) -> f32 {
474 }
488 }
475}
489}
476
490
477fn bubble_meta(row: &MessageRow, own: bool, saved: bool) -> Div {
491/// A negative margin drops the whole row from taffy's max-content width, so the meta moves into the padding by offset.
492fn shifted_right(meta: Div, jumbo: bool) -> Div {
493 let shift = meta_right_shift(jumbo);
494 if shift < 0. {
495 let into_padding = shift.abs();
496 meta.relative().left(px(into_padding))
497 } else {
498 meta.mr(px(shift))
499 }
500}
501
502fn bubble_meta(row: &MessageRow, index: usize, own: bool, saved: bool) -> Div {
478 let tint = if own {
503 let tint = if own {
479 theme::own_meta()
504 theme::own_meta()
480 } else {
505 } else {
481 theme::text_muted()
506 theme::text_muted()
482 };
507 };
483 h_flex()
508 h_flex()
509 .when_some(BUBBLE_META_TAGS.get(index).copied(), |meta, tag| {
510 meta.debug_selector(|| tag.into())
511 })
484 .gap(px(4.))
512 .gap(px(4.))
485 .items_center()
513 .items_center()
486 .text_size(px(META_SIZE))
514 .text_size(px(META_SIZE))