BlueGit

ict rusty-teams

fix(conversation): hover toolbar stays when the pointer moves onto it

- gpui reports the toolbar enter before the row leave on the same move; the row leave then hid the toolbar after the grace
- Row and toolbar each track whether the pointer is on them; the grace only starts when neither holds the message

Fixes #59

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-17 · 2 weeks ago

Hash
5a11426a90fb8da64a2ee9755c8d3de17f11dbd3
Parent
72edd824
1 file changed +40 −3
crates/app/src/views/conversation.rs +40 −3
@@ -166,6 +166,27 @@ enum HoverSlot {
166 166 Toolbar,
167 167 }
168 168
169 /// Where the pointer is right now. A move from a row onto its toolbar reports the toolbar
170 /// enter before the row leave, so a leave only starts the grace when neither part holds it.
171 #[derive(Default)]
172 struct PointerOn {
173 row: Option<String>,
174 toolbar: Option<String>,
175 }
176
177 impl PointerOn {
178 fn slot(&mut self, slot: HoverSlot) -> &mut Option<String> {
179 match slot {
180 HoverSlot::Row => &mut self.row,
181 HoverSlot::Toolbar => &mut self.toolbar,
182 }
183 }
184
185 fn holds(&self, key: &str) -> bool {
186 self.row.as_deref() == Some(key) || self.toolbar.as_deref() == Some(key)
187 }
188 }
189
169 190 #[derive(Debug, Clone, PartialEq, Eq)]
170 191 enum ViewMode {
171 192 Flat,
@@ -254,6 +275,7 @@ pub struct ConversationView {
254 275 downloads: Downloads,
255 276 hovered_message: Option<String>,
256 277 hover_leave_serial: u64,
278 pointer_on: PointerOn,
257 279 toolbar_hovered: Option<String>,
258 280 context_menu: Option<OpenContextMenu>,
259 281 context_serial: u64,
@@ -735,6 +757,7 @@ impl ConversationView {
735 757 downloads: Downloads::default(),
736 758 hovered_message: None,
737 759 hover_leave_serial: 0,
760 pointer_on: PointerOn::default(),
738 761 toolbar_hovered: None,
739 762 context_menu: None,
740 763 context_serial: 0,
@@ -1165,6 +1188,7 @@ impl ConversationView {
1165 1188 .update(cx, |composer, cx| composer.focus(window, cx));
1166 1189 }
1167 1190 self.hovered_message = None;
1191 self.pointer_on = PointerOn::default();
1168 1192 self.apply_pending_jump(cx);
1169 1193 }
1170 1194
@@ -1181,6 +1205,7 @@ impl ConversationView {
1181 1205 self.toolbar_pinned = None;
1182 1206 self.toolbar_suppressed = None;
1183 1207 self.hovered_message = None;
1208 self.pointer_on = PointerOn::default();
1184 1209 self.sync_generation += 1;
1185 1210 self.draft.update(cx, |draft, cx| draft.reset(window, cx));
1186 1211 self.composer
@@ -3066,14 +3091,20 @@ impl ConversationView {
3066 3091 if hovered && matches!(slot, HoverSlot::Row) {
3067 3092 self.request_post_follow(key, cx);
3068 3093 }
3094 let pointer = self.pointer_on.slot(slot);
3069 3095 if !hovered {
3070 if self.hovered_message.as_deref() == Some(key)
3071 || self.toolbar_hovered.as_deref() == Some(key)
3096 if pointer.as_deref() == Some(key) {
3097 *pointer = None;
3098 }
3099 if !self.pointer_on.holds(key)
3100 && (self.hovered_message.as_deref() == Some(key)
3101 || self.toolbar_hovered.as_deref() == Some(key))
3072 3102 {
3073 3103 self.leave_hover_later(key.to_owned(), cx);
3074 3104 }
3075 3105 return;
3076 3106 }
3107 *pointer = Some(key.to_owned());
3077 3108 self.hover_leave_serial += 1;
3078 3109 match slot {
3079 3110 HoverSlot::Row => self.hovered_message = Some(key.to_owned()),
@@ -3102,7 +3133,7 @@ impl ConversationView {
3102 3133 cx.spawn(async move |this, cx| {
3103 3134 cx.background_executor().timer(HOVER_LEAVE_GRACE).await;
3104 3135 this.update(cx, |this, cx| {
3105 if this.hover_leave_serial != serial {
3136 if this.hover_leave_serial != serial || this.pointer_on.holds(&key) {
3106 3137 return;
3107 3138 }
3108 3139 if this.hovered_message.as_deref() == Some(key.as_str()) {
@@ -3122,6 +3153,7 @@ impl ConversationView {
3122 3153 }
3123 3154
3124 3155 fn suppress_toolbar(&mut self, key: &str, cx: &mut Context<Self>) {
3156 self.pointer_on.toolbar = None;
3125 3157 if self.toolbar_hovered.as_deref() == Some(key) {
3126 3158 self.toolbar_hovered = None;
3127 3159 }
@@ -4818,6 +4850,11 @@ mod tests {
4818 4850 assert_eq!(shown(cx).0.as_deref(), Some("b"));
4819 4851 cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);
4820 4852 assert_eq!(shown(cx).0.as_deref(), Some("b"));
4853 hover(cx, HoverSlot::Row, "c", true);
4854 hover(cx, HoverSlot::Toolbar, "c", true);
4855 hover(cx, HoverSlot::Row, "c", false);
4856 cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);
4857 assert_eq!(shown(cx).1.as_deref(), Some("c"));
4821 4858 }
4822 4859
4823 4860 #[gpui_kit::test]
@@ -166,6 +166,27 @@ enum HoverSlot {
166 Toolbar,
166 Toolbar,
167}
167}
168
168
169/// Where the pointer is right now. A move from a row onto its toolbar reports the toolbar
170/// enter before the row leave, so a leave only starts the grace when neither part holds it.
171#[derive(Default)]
172struct PointerOn {
173 row: Option<String>,
174 toolbar: Option<String>,
175}
176
177impl PointerOn {
178 fn slot(&mut self, slot: HoverSlot) -> &mut Option<String> {
179 match slot {
180 HoverSlot::Row => &mut self.row,
181 HoverSlot::Toolbar => &mut self.toolbar,
182 }
183 }
184
185 fn holds(&self, key: &str) -> bool {
186 self.row.as_deref() == Some(key) || self.toolbar.as_deref() == Some(key)
187 }
188}
189
169#[derive(Debug, Clone, PartialEq, Eq)]
190#[derive(Debug, Clone, PartialEq, Eq)]
170enum ViewMode {
191enum ViewMode {
171 Flat,
192 Flat,
@@ -254,6 +275,7 @@ pub struct ConversationView {
254 downloads: Downloads,
275 downloads: Downloads,
255 hovered_message: Option<String>,
276 hovered_message: Option<String>,
256 hover_leave_serial: u64,
277 hover_leave_serial: u64,
278 pointer_on: PointerOn,
257 toolbar_hovered: Option<String>,
279 toolbar_hovered: Option<String>,
258 context_menu: Option<OpenContextMenu>,
280 context_menu: Option<OpenContextMenu>,
259 context_serial: u64,
281 context_serial: u64,
@@ -735,6 +757,7 @@ impl ConversationView {
735 downloads: Downloads::default(),
757 downloads: Downloads::default(),
736 hovered_message: None,
758 hovered_message: None,
737 hover_leave_serial: 0,
759 hover_leave_serial: 0,
760 pointer_on: PointerOn::default(),
738 toolbar_hovered: None,
761 toolbar_hovered: None,
739 context_menu: None,
762 context_menu: None,
740 context_serial: 0,
763 context_serial: 0,
@@ -1165,6 +1188,7 @@ impl ConversationView {
1165 .update(cx, |composer, cx| composer.focus(window, cx));
1188 .update(cx, |composer, cx| composer.focus(window, cx));
1166 }
1189 }
1167 self.hovered_message = None;
1190 self.hovered_message = None;
1191 self.pointer_on = PointerOn::default();
1168 self.apply_pending_jump(cx);
1192 self.apply_pending_jump(cx);
1169 }
1193 }
1170
1194
@@ -1181,6 +1205,7 @@ impl ConversationView {
1181 self.toolbar_pinned = None;
1205 self.toolbar_pinned = None;
1182 self.toolbar_suppressed = None;
1206 self.toolbar_suppressed = None;
1183 self.hovered_message = None;
1207 self.hovered_message = None;
1208 self.pointer_on = PointerOn::default();
1184 self.sync_generation += 1;
1209 self.sync_generation += 1;
1185 self.draft.update(cx, |draft, cx| draft.reset(window, cx));
1210 self.draft.update(cx, |draft, cx| draft.reset(window, cx));
1186 self.composer
1211 self.composer
@@ -3066,14 +3091,20 @@ impl ConversationView {
3066 if hovered && matches!(slot, HoverSlot::Row) {
3091 if hovered && matches!(slot, HoverSlot::Row) {
3067 self.request_post_follow(key, cx);
3092 self.request_post_follow(key, cx);
3068 }
3093 }
3094 let pointer = self.pointer_on.slot(slot);
3069 if !hovered {
3095 if !hovered {
3070 if self.hovered_message.as_deref() == Some(key)
3096 if pointer.as_deref() == Some(key) {
3071 || self.toolbar_hovered.as_deref() == Some(key)
3097 *pointer = None;
3098 }
3099 if !self.pointer_on.holds(key)
3100 && (self.hovered_message.as_deref() == Some(key)
3101 || self.toolbar_hovered.as_deref() == Some(key))
3072 {
3102 {
3073 self.leave_hover_later(key.to_owned(), cx);
3103 self.leave_hover_later(key.to_owned(), cx);
3074 }
3104 }
3075 return;
3105 return;
3076 }
3106 }
3107 *pointer = Some(key.to_owned());
3077 self.hover_leave_serial += 1;
3108 self.hover_leave_serial += 1;
3078 match slot {
3109 match slot {
3079 HoverSlot::Row => self.hovered_message = Some(key.to_owned()),
3110 HoverSlot::Row => self.hovered_message = Some(key.to_owned()),
@@ -3102,7 +3133,7 @@ impl ConversationView {
3102 cx.spawn(async move |this, cx| {
3133 cx.spawn(async move |this, cx| {
3103 cx.background_executor().timer(HOVER_LEAVE_GRACE).await;
3134 cx.background_executor().timer(HOVER_LEAVE_GRACE).await;
3104 this.update(cx, |this, cx| {
3135 this.update(cx, |this, cx| {
3105 if this.hover_leave_serial != serial {
3136 if this.hover_leave_serial != serial || this.pointer_on.holds(&key) {
3106 return;
3137 return;
3107 }
3138 }
3108 if this.hovered_message.as_deref() == Some(key.as_str()) {
3139 if this.hovered_message.as_deref() == Some(key.as_str()) {
@@ -3122,6 +3153,7 @@ impl ConversationView {
3122 }
3153 }
3123
3154
3124 fn suppress_toolbar(&mut self, key: &str, cx: &mut Context<Self>) {
3155 fn suppress_toolbar(&mut self, key: &str, cx: &mut Context<Self>) {
3156 self.pointer_on.toolbar = None;
3125 if self.toolbar_hovered.as_deref() == Some(key) {
3157 if self.toolbar_hovered.as_deref() == Some(key) {
3126 self.toolbar_hovered = None;
3158 self.toolbar_hovered = None;
3127 }
3159 }
@@ -4818,6 +4850,11 @@ mod tests {
4818 assert_eq!(shown(cx).0.as_deref(), Some("b"));
4850 assert_eq!(shown(cx).0.as_deref(), Some("b"));
4819 cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);
4851 cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);
4820 assert_eq!(shown(cx).0.as_deref(), Some("b"));
4852 assert_eq!(shown(cx).0.as_deref(), Some("b"));
4853 hover(cx, HoverSlot::Row, "c", true);
4854 hover(cx, HoverSlot::Toolbar, "c", true);
4855 hover(cx, HoverSlot::Row, "c", false);
4856 cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);
4857 assert_eq!(shown(cx).1.as_deref(), Some("c"));
4821 }
4858 }
4822
4859
4823 #[gpui_kit::test]
4860 #[gpui_kit::test]