fix(conversation): hover toolbar stays 250 ms after the pointer leaves
- Leaving a message or its toolbar hides the toolbar after a 250 ms grace, so the pointer can reach it - Hovering another message moves the toolbar at once; only one toolbar is shown Fixes #50 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -118,6 +118,7 @@ pub const HEADER_DIVIDER: &str = "shell/islands/main/divider-header";
118
118
pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";
119
119
pub const FEED_EDGE_TAG: &str = "shell/islands/main/timeline/divider-feed";
120
120
const SENT_PREVIEWS_KEPT: usize = 16;
121
const HOVER_LEAVE_GRACE: Duration = Duration::from_millis(250);
121
122
const POSTED_WITHOUT_BANNER: &str = "Posted, but Teams did not take the banner.";
122
123
const QUIET_RETRY_DELAYS: [Duration; 3] = [
123
124
Duration::from_secs(2),
@@ -251,6 +252,7 @@ pub struct ConversationView {
251
252
pending_reactions: PendingReactions,
252
253
downloads: Downloads,
253
254
hovered_message: Option<String>,
255
hover_leave_serial: u64,
254
256
toolbar_hovered: Option<String>,
255
257
context_menu: Option<OpenContextMenu>,
256
258
context_serial: u64,
@@ -701,6 +703,7 @@ impl ConversationView {
701
703
pending_reactions: HashMap::new(),
702
704
downloads: Downloads::default(),
703
705
hovered_message: None,
706
hover_leave_serial: 0,
704
707
toolbar_hovered: None,
705
708
context_menu: None,
706
709
context_serial: 0,
@@ -3019,23 +3022,20 @@ impl ConversationView {
3019
3022
if hovered && matches!(slot, HoverSlot::Row) {
3020
3023
self.request_post_follow(key, cx);
3021
3024
}
3022
let target = match slot {
3023
HoverSlot::Row => &mut self.hovered_message,
3024
HoverSlot::Toolbar => &mut self.toolbar_hovered,
3025
};
3026
if hovered {
3027
*target = Some(key.to_owned());
3028
} else if target.as_deref() == Some(key) {
3029
*target = None;
3030
}
3031
if !hovered
3032
&& matches!(slot, HoverSlot::Row)
3033
&& self.toolbar_hovered.as_deref() == Some(key)
3034
{
3035
self.toolbar_hovered = None;
3025
if !hovered {
3026
if self.hovered_message.as_deref() == Some(key)
3027
|| self.toolbar_hovered.as_deref() == Some(key)
3028
{
3029
self.leave_hover_later(key.to_owned(), cx);
3030
}
3031
return;
3032
}
3033
self.hover_leave_serial += 1;
3034
match slot {
3035
HoverSlot::Row => self.hovered_message = Some(key.to_owned()),
3036
HoverSlot::Toolbar => self.toolbar_hovered = Some(key.to_owned()),
3036
3037
}
3037
if hovered
3038
&& matches!(slot, HoverSlot::Row)
3038
if matches!(slot, HoverSlot::Row)
3039
3039
&& self
3040
3040
.toolbar_hovered
3041
3041
.as_deref()
@@ -3052,6 +3052,31 @@ impl ConversationView {
3052
3052
cx.notify();
3053
3053
}
3054
3054
3055
fn leave_hover_later(&mut self, key: String, cx: &mut Context<Self>) {
3056
self.hover_leave_serial += 1;
3057
let serial = self.hover_leave_serial;
3058
cx.spawn(async move |this, cx| {
3059
cx.background_executor().timer(HOVER_LEAVE_GRACE).await;
3060
this.update(cx, |this, cx| {
3061
if this.hover_leave_serial != serial {
3062
return;
3063
}
3064
if this.hovered_message.as_deref() == Some(key.as_str()) {
3065
this.hovered_message = None;
3066
}
3067
if this.toolbar_hovered.as_deref() == Some(key.as_str()) {
3068
this.toolbar_hovered = None;
3069
}
3070
if this.toolbar_suppressed.as_deref() == Some(key.as_str()) {
3071
this.toolbar_suppressed = None;
3072
}
3073
cx.notify();
3074
})
3075
.ok();
3076
})
3077
.detach();
3078
}
3079
3055
3080
fn suppress_toolbar(&mut self, key: &str, cx: &mut Context<Self>) {
3056
3081
if self.toolbar_hovered.as_deref() == Some(key) {
3057
3082
self.toolbar_hovered = None;
@@ -4671,7 +4696,9 @@ fn runway(content: impl IntoElement, comfy: bool) -> AnyElement {
4671
4696
mod tests {
4672
4697
use std::sync::Arc;
4673
4698
4674
use super::{DropTarget, drop_overlay_text, typing_bottom_offset};
4699
use super::{
4700
DropTarget, HOVER_LEAVE_GRACE, HoverSlot, drop_overlay_text, typing_bottom_offset,
4701
};
4675
4702
4676
4703
use gpui_kit::test::TestWindowExt as _;
4677
4704
use gpui_kit::{AppContext as _, TestAppContext, WindowOptions};
@@ -4710,6 +4737,45 @@ mod tests {
4710
4737
);
4711
4738
}
4712
4739
4740
#[gpui_kit::test]
4741
fn the_toolbar_outlives_a_short_leave_and_moves_at_once(cx: &mut TestAppContext) {
4742
cx.update(gpui_kit::init);
4743
let store = Arc::new(Store::open_in_memory().unwrap());
4744
crate::demo::seed(&store);
4745
let view = cx.update(|cx| {
4746
let app = cx.new(|_| AppState::new(store, Mode::default()));
4747
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
4748
cx.new(|cx| ConversationView::new(app, window, cx))
4749
})
4750
.unwrap()
4751
.1
4752
});
4753
let hover = |cx: &mut TestAppContext, slot: HoverSlot, key: &str, hovered: bool| {
4754
cx.update(|cx| view.update(cx, |this, cx| this.set_hover(slot, key, hovered, cx)));
4755
};
4756
let shown = |cx: &mut TestAppContext| {
4757
cx.update(|cx| {
4758
let this = view.read(cx);
4759
(this.hovered_message.clone(), this.toolbar_hovered.clone())
4760
})
4761
};
4762
hover(cx, HoverSlot::Row, "a", true);
4763
hover(cx, HoverSlot::Row, "a", false);
4764
assert_eq!(shown(cx).0.as_deref(), Some("a"));
4765
hover(cx, HoverSlot::Toolbar, "a", true);
4766
cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);
4767
assert_eq!(shown(cx), (Some("a".into()), Some("a".into())));
4768
hover(cx, HoverSlot::Toolbar, "a", false);
4769
cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);
4770
assert_eq!(shown(cx), (None, None));
4771
hover(cx, HoverSlot::Row, "a", true);
4772
hover(cx, HoverSlot::Row, "a", false);
4773
hover(cx, HoverSlot::Row, "b", true);
4774
assert_eq!(shown(cx).0.as_deref(), Some("b"));
4775
cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);
4776
assert_eq!(shown(cx).0.as_deref(), Some("b"));
4777
}
4778
4713
4779
#[gpui_kit::test]
4714
4780
fn demo_draft_creates_a_chat_and_selects_it(cx: &mut TestAppContext) {
4715
4781
cx.update(gpui_kit::init);
@@ -118,6 +118,7 @@ pub const HEADER_DIVIDER: &str = "shell/islands/main/divider-header";118
pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";118
pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";119
pub const FEED_EDGE_TAG: &str = "shell/islands/main/timeline/divider-feed";119
pub const FEED_EDGE_TAG: &str = "shell/islands/main/timeline/divider-feed";120
const SENT_PREVIEWS_KEPT: usize = 16;120
const SENT_PREVIEWS_KEPT: usize = 16;121
const HOVER_LEAVE_GRACE: Duration = Duration::from_millis(250);121
const POSTED_WITHOUT_BANNER: &str = "Posted, but Teams did not take the banner.";122
const POSTED_WITHOUT_BANNER: &str = "Posted, but Teams did not take the banner.";122
const QUIET_RETRY_DELAYS: [Duration; 3] = [123
const QUIET_RETRY_DELAYS: [Duration; 3] = [123
Duration::from_secs(2),124
Duration::from_secs(2),@@ -251,6 +252,7 @@ pub struct ConversationView {251
pending_reactions: PendingReactions,252
pending_reactions: PendingReactions,252
downloads: Downloads,253
downloads: Downloads,253
hovered_message: Option<String>,254
hovered_message: Option<String>,255
hover_leave_serial: u64,254
toolbar_hovered: Option<String>,256
toolbar_hovered: Option<String>,255
context_menu: Option<OpenContextMenu>,257
context_menu: Option<OpenContextMenu>,256
context_serial: u64,258
context_serial: u64,@@ -701,6 +703,7 @@ impl ConversationView {701
pending_reactions: HashMap::new(),703
pending_reactions: HashMap::new(),702
downloads: Downloads::default(),704
downloads: Downloads::default(),703
hovered_message: None,705
hovered_message: None,706
hover_leave_serial: 0,704
toolbar_hovered: None,707
toolbar_hovered: None,705
context_menu: None,708
context_menu: None,706
context_serial: 0,709
context_serial: 0,@@ -3019,23 +3022,20 @@ impl ConversationView {3019
if hovered && matches!(slot, HoverSlot::Row) {3022
if hovered && matches!(slot, HoverSlot::Row) {3020
self.request_post_follow(key, cx);3023
self.request_post_follow(key, cx);3021
}3024
}3022
let target = match slot {3025
if !hovered {3023
HoverSlot::Row => &mut self.hovered_message,3026
if self.hovered_message.as_deref() == Some(key)3024
HoverSlot::Toolbar => &mut self.toolbar_hovered,3027
|| self.toolbar_hovered.as_deref() == Some(key)3025
};3028
{3026
if hovered {3029
self.leave_hover_later(key.to_owned(), cx);3027
*target = Some(key.to_owned());3030
}3028
} else if target.as_deref() == Some(key) {3031
return;3029
*target = None;3032
}3030
}3033
self.hover_leave_serial += 1;3031
if !hovered3034
match slot {3032
&& matches!(slot, HoverSlot::Row)3035
HoverSlot::Row => self.hovered_message = Some(key.to_owned()),3033
&& self.toolbar_hovered.as_deref() == Some(key)3036
HoverSlot::Toolbar => self.toolbar_hovered = Some(key.to_owned()),3034
{3035
self.toolbar_hovered = None;3036
}3037
}3037
if hovered3038
if matches!(slot, HoverSlot::Row)3038
&& matches!(slot, HoverSlot::Row)3039
&& self3039
&& self3040
.toolbar_hovered3040
.toolbar_hovered3041
.as_deref()3041
.as_deref()@@ -3052,6 +3052,31 @@ impl ConversationView {3052
cx.notify();3052
cx.notify();3053
}3053
}3054
3054
3055
fn leave_hover_later(&mut self, key: String, cx: &mut Context<Self>) {3056
self.hover_leave_serial += 1;3057
let serial = self.hover_leave_serial;3058
cx.spawn(async move |this, cx| {3059
cx.background_executor().timer(HOVER_LEAVE_GRACE).await;3060
this.update(cx, |this, cx| {3061
if this.hover_leave_serial != serial {3062
return;3063
}3064
if this.hovered_message.as_deref() == Some(key.as_str()) {3065
this.hovered_message = None;3066
}3067
if this.toolbar_hovered.as_deref() == Some(key.as_str()) {3068
this.toolbar_hovered = None;3069
}3070
if this.toolbar_suppressed.as_deref() == Some(key.as_str()) {3071
this.toolbar_suppressed = None;3072
}3073
cx.notify();3074
})3075
.ok();3076
})3077
.detach();3078
}3079
3055
fn suppress_toolbar(&mut self, key: &str, cx: &mut Context<Self>) {3080
fn suppress_toolbar(&mut self, key: &str, cx: &mut Context<Self>) {3056
if self.toolbar_hovered.as_deref() == Some(key) {3081
if self.toolbar_hovered.as_deref() == Some(key) {3057
self.toolbar_hovered = None;3082
self.toolbar_hovered = None;@@ -4671,7 +4696,9 @@ fn runway(content: impl IntoElement, comfy: bool) -> AnyElement {4671
mod tests {4696
mod tests {4672
use std::sync::Arc;4697
use std::sync::Arc;4673
4698
4674
use super::{DropTarget, drop_overlay_text, typing_bottom_offset};4699
use super::{4700
DropTarget, HOVER_LEAVE_GRACE, HoverSlot, drop_overlay_text, typing_bottom_offset,4701
};4675
4702
4676
use gpui_kit::test::TestWindowExt as _;4703
use gpui_kit::test::TestWindowExt as _;4677
use gpui_kit::{AppContext as _, TestAppContext, WindowOptions};4704
use gpui_kit::{AppContext as _, TestAppContext, WindowOptions};@@ -4710,6 +4737,45 @@ mod tests {4710
);4737
);4711
}4738
}4712
4739
4740
#[gpui_kit::test]4741
fn the_toolbar_outlives_a_short_leave_and_moves_at_once(cx: &mut TestAppContext) {4742
cx.update(gpui_kit::init);4743
let store = Arc::new(Store::open_in_memory().unwrap());4744
crate::demo::seed(&store);4745
let view = cx.update(|cx| {4746
let app = cx.new(|_| AppState::new(store, Mode::default()));4747
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {4748
cx.new(|cx| ConversationView::new(app, window, cx))4749
})4750
.unwrap()4751
.14752
});4753
let hover = |cx: &mut TestAppContext, slot: HoverSlot, key: &str, hovered: bool| {4754
cx.update(|cx| view.update(cx, |this, cx| this.set_hover(slot, key, hovered, cx)));4755
};4756
let shown = |cx: &mut TestAppContext| {4757
cx.update(|cx| {4758
let this = view.read(cx);4759
(this.hovered_message.clone(), this.toolbar_hovered.clone())4760
})4761
};4762
hover(cx, HoverSlot::Row, "a", true);4763
hover(cx, HoverSlot::Row, "a", false);4764
assert_eq!(shown(cx).0.as_deref(), Some("a"));4765
hover(cx, HoverSlot::Toolbar, "a", true);4766
cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);4767
assert_eq!(shown(cx), (Some("a".into()), Some("a".into())));4768
hover(cx, HoverSlot::Toolbar, "a", false);4769
cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);4770
assert_eq!(shown(cx), (None, None));4771
hover(cx, HoverSlot::Row, "a", true);4772
hover(cx, HoverSlot::Row, "a", false);4773
hover(cx, HoverSlot::Row, "b", true);4774
assert_eq!(shown(cx).0.as_deref(), Some("b"));4775
cx.executor().advance_clock(HOVER_LEAVE_GRACE * 2);4776
assert_eq!(shown(cx).0.as_deref(), Some("b"));4777
}4778
4713
#[gpui_kit::test]4779
#[gpui_kit::test]4714
fn demo_draft_creates_a_chat_and_selects_it(cx: &mut TestAppContext) {4780
fn demo_draft_creates_a_chat_and_selects_it(cx: &mut TestAppContext) {4715
cx.update(gpui_kit::init);4781
cx.update(gpui_kit::init);