diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 303c96a..0fd8f82 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -254,6 +254,8 @@ pub struct Chat { pub(super) builder_attachments: Vec, pub(super) pending_attachment_delete: Option, pub(super) pending_message_delete: Option, + pub(super) hover_row: Option, + pub(super) hover_bar: Option, pub(super) pending_builder_purge: Option, pub(super) transfer: Option, pub(super) voice: HashMap>, @@ -502,6 +504,8 @@ impl Chat { builder_attachments: vec![], pending_attachment_delete: None, pending_message_delete: None, + hover_row: None, + hover_bar: None, pending_builder_purge: None, transfer: None, builder_password, @@ -3539,6 +3543,17 @@ fn render_message( let row = div() .id(format!("message_row_{}", message.id)) .group(group.clone()) + .on_hover({ + let entity = entity.clone(); + let id = message.id; + move |hovered, _, cx| { + entity.update(cx, |yumush, cx| { + if message_actions::track(&mut yumush.chat.hover_row, id, *hovered) { + cx.notify(); + } + }); + } + }) .relative() .flex() .flex_col() @@ -3665,10 +3680,8 @@ fn render_message( div() .absolute() .right_0() - .top_0() - .child(message_actions::actions( - message, chat, me, entity, palette, group, - )) + .top(px(-space::LG)) + .child(message_actions::actions(message, chat, me, entity, palette)) })), ) .children( diff --git a/crates/client/src/gui/message_actions.rs b/crates/client/src/gui/message_actions.rs index 29da862..db55311 100644 --- a/crates/client/src/gui/message_actions.rs +++ b/crates/client/src/gui/message_actions.rs @@ -8,7 +8,7 @@ use common::{ }; use gpui_kit::{ Anchor, Context, Div, Entity, Focusable as _, FontWeight, InteractiveElement, IntoElement, - ParentElement, Stateful, Styled, Window, + ParentElement, Stateful, StatefulInteractiveElement as _, Styled, Window, assets::IconName, component::{ input::InputState, @@ -410,7 +410,6 @@ pub fn actions( me: Option<&User>, entity: &Entity, palette: Palette, - group: String, ) -> impl IntoElement { let mine = me.is_some_and(|me| me.id == message.user_id); let editable = mine && !message.body.is_empty() && message.snippet.is_none(); @@ -419,14 +418,31 @@ pub fn actions( let reportable = me.is_some_and(|me| me.id != message.user_id); let id = message.id; let armed = chat.pending_message_delete == Some(id); + let shown = armed || chat.hover_row == Some(id) || chat.hover_bar == Some(id); + let hover = entity.clone(); panel(palette) + .id(format!("message_actions_{id}")) .flex() .items_center() .gap(px(space::XXS)) .p(px(space::XXS)) - .when(!armed, |this| this.invisible()) - .group_hover(group, |style| style.visible()) + .map(|this| { + if shown { + this.occlude() + } else { + this.invisible() + } + }) + .on_hover(move |hovered, _, cx| { + if shown || !*hovered { + hover.update(cx, |yumush, cx| { + if track(&mut yumush.chat.hover_bar, id, *hovered) { + cx.notify(); + } + }); + } + }) .child(action( entity, palette, @@ -646,3 +662,14 @@ fn action( }, ) } + +pub fn track(slot: &mut Option, id: Id, hovered: bool) -> bool { + let next = match (hovered, *slot == Some(id)) { + (true, _) => Some(id), + (false, true) => None, + (false, false) => *slot, + }; + let changed = next != *slot; + *slot = next; + changed +}