Message actions bar back above the message and reachable: shown while the pointer is on its message or on the bar itself (hover tracked in state)
Browse files at this commitf6f981882a3e60058d66cd0a5d984ce7c43bebbdParent: a7e06af- fix
- message actions bar back above the message and reachable: shown while the pointer is on its message or on the bar itself (hover tracked in state)
- a hidden bar ignores hover and doesn't block what's under it
2 changed files +48 -8
crates/client/src/gui/chat.rsmodified+17 -4
| @@ -254,6 +254,8 @@ pub struct Chat { | |||
| 254 | pub(super) builder_attachments: Vec<AttachmentInfo>, | 254 | pub(super) builder_attachments: Vec<AttachmentInfo>, |
| 255 | pub(super) pending_attachment_delete: Option<Id>, | 255 | pub(super) pending_attachment_delete: Option<Id>, |
| 256 | pub(super) pending_message_delete: Option<Id>, | 256 | pub(super) pending_message_delete: Option<Id>, |
| 257 | + pub(super) hover_row: Option<Id>, | ||
| 258 | + pub(super) hover_bar: Option<Id>, | ||
| 257 | pub(super) pending_builder_purge: Option<Id>, | 259 | pub(super) pending_builder_purge: Option<Id>, |
| 258 | pub(super) transfer: Option<Transfer>, | 260 | pub(super) transfer: Option<Transfer>, |
| 259 | pub(super) voice: HashMap<Id, Vec<Id>>, | 261 | pub(super) voice: HashMap<Id, Vec<Id>>, |
| @@ -502,6 +504,8 @@ impl Chat { | |||
| 502 | builder_attachments: vec![], | 504 | builder_attachments: vec![], |
| 503 | pending_attachment_delete: None, | 505 | pending_attachment_delete: None, |
| 504 | pending_message_delete: None, | 506 | pending_message_delete: None, |
| 507 | + hover_row: None, | ||
| 508 | + hover_bar: None, | ||
| 505 | pending_builder_purge: None, | 509 | pending_builder_purge: None, |
| 506 | transfer: None, | 510 | transfer: None, |
| 507 | builder_password, | 511 | builder_password, |
| @@ -3539,6 +3543,17 @@ fn render_message( | |||
| 3539 | let row = div() | 3543 | let row = div() |
| 3540 | .id(format!("message_row_{}", message.id)) | 3544 | .id(format!("message_row_{}", message.id)) |
| 3541 | .group(group.clone()) | 3545 | .group(group.clone()) |
| 3546 | + .on_hover({ | ||
| 3547 | + let entity = entity.clone(); | ||
| 3548 | + let id = message.id; | ||
| 3549 | + move |hovered, _, cx| { | ||
| 3550 | + entity.update(cx, |yumush, cx| { | ||
| 3551 | + if message_actions::track(&mut yumush.chat.hover_row, id, *hovered) { | ||
| 3552 | + cx.notify(); | ||
| 3553 | + } | ||
| 3554 | + }); | ||
| 3555 | + } | ||
| 3556 | + }) | ||
| 3542 | .relative() | 3557 | .relative() |
| 3543 | .flex() | 3558 | .flex() |
| 3544 | .flex_col() | 3559 | .flex_col() |
| @@ -3665,10 +3680,8 @@ fn render_message( | |||
| 3665 | div() | 3680 | div() |
| 3666 | .absolute() | 3681 | .absolute() |
| 3667 | .right_0() | 3682 | .right_0() |
| 3668 | - .top_0() | 3683 | + .top(px(-space::LG)) |
| 3669 | - .child(message_actions::actions( | 3684 | + .child(message_actions::actions(message, chat, me, entity, palette)) |
| 3670 | - message, chat, me, entity, palette, group, | ||
| 3671 | - )) | ||
| 3672 | })), | 3685 | })), |
| 3673 | ) | 3686 | ) |
| 3674 | .children( | 3687 | .children( |
crates/client/src/gui/message_actions.rsmodified+31 -4
| @@ -8,7 +8,7 @@ use common::{ | |||
| 8 | }; | 8 | }; |
| 9 | use gpui_kit::{ | 9 | use gpui_kit::{ |
| 10 | Anchor, Context, Div, Entity, Focusable as _, FontWeight, InteractiveElement, IntoElement, | 10 | Anchor, Context, Div, Entity, Focusable as _, FontWeight, InteractiveElement, IntoElement, |
| 11 | - ParentElement, Stateful, Styled, Window, | 11 | + ParentElement, Stateful, StatefulInteractiveElement as _, Styled, Window, |
| 12 | assets::IconName, | 12 | assets::IconName, |
| 13 | component::{ | 13 | component::{ |
| 14 | input::InputState, | 14 | input::InputState, |
| @@ -410,7 +410,6 @@ pub fn actions( | |||
| 410 | me: Option<&User>, | 410 | me: Option<&User>, |
| 411 | entity: &Entity<Yumush>, | 411 | entity: &Entity<Yumush>, |
| 412 | palette: Palette, | 412 | palette: Palette, |
| 413 | - group: String, | ||
| 414 | ) -> impl IntoElement { | 413 | ) -> impl IntoElement { |
| 415 | let mine = me.is_some_and(|me| me.id == message.user_id); | 414 | let mine = me.is_some_and(|me| me.id == message.user_id); |
| 416 | let editable = mine && !message.body.is_empty() && message.snippet.is_none(); | 415 | let editable = mine && !message.body.is_empty() && message.snippet.is_none(); |
| @@ -419,14 +418,31 @@ pub fn actions( | |||
| 419 | let reportable = me.is_some_and(|me| me.id != message.user_id); | 418 | let reportable = me.is_some_and(|me| me.id != message.user_id); |
| 420 | let id = message.id; | 419 | let id = message.id; |
| 421 | let armed = chat.pending_message_delete == Some(id); | 420 | let armed = chat.pending_message_delete == Some(id); |
| 421 | + let shown = armed || chat.hover_row == Some(id) || chat.hover_bar == Some(id); | ||
| 422 | + let hover = entity.clone(); | ||
| 422 | 423 | ||
| 423 | panel(palette) | 424 | panel(palette) |
| 425 | + .id(format!("message_actions_{id}")) | ||
| 424 | .flex() | 426 | .flex() |
| 425 | .items_center() | 427 | .items_center() |
| 426 | .gap(px(space::XXS)) | 428 | .gap(px(space::XXS)) |
| 427 | .p(px(space::XXS)) | 429 | .p(px(space::XXS)) |
| 428 | - .when(!armed, |this| this.invisible()) | 430 | + .map(|this| { |
| 429 | - .group_hover(group, |style| style.visible()) | 431 | + if shown { |
| 432 | + this.occlude() | ||
| 433 | + } else { | ||
| 434 | + this.invisible() | ||
| 435 | + } | ||
| 436 | + }) | ||
| 437 | + .on_hover(move |hovered, _, cx| { | ||
| 438 | + if shown || !*hovered { | ||
| 439 | + hover.update(cx, |yumush, cx| { | ||
| 440 | + if track(&mut yumush.chat.hover_bar, id, *hovered) { | ||
| 441 | + cx.notify(); | ||
| 442 | + } | ||
| 443 | + }); | ||
| 444 | + } | ||
| 445 | + }) | ||
| 430 | .child(action( | 446 | .child(action( |
| 431 | entity, | 447 | entity, |
| 432 | palette, | 448 | palette, |
| @@ -646,3 +662,14 @@ fn action( | |||
| 646 | }, | 662 | }, |
| 647 | ) | 663 | ) |
| 648 | } | 664 | } |
| 665 | + | ||
| 666 | +pub fn track(slot: &mut Option<Id>, id: Id, hovered: bool) -> bool { | ||
| 667 | + let next = match (hovered, *slot == Some(id)) { | ||
| 668 | + (true, _) => Some(id), | ||
| 669 | + (false, true) => None, | ||
| 670 | + (false, false) => *slot, | ||
| 671 | + }; | ||
| 672 | + let changed = next != *slot; | ||
| 673 | + *slot = next; | ||
| 674 | + changed | ||
| 675 | +} | ||