BlueGit

ict rusty-teams

fix(notify): clicking the toast reply input no longer opens the chat

- reply field (input, hints, disabled send) stops click propagation to the toast card
- gpui test: click into the reply input keeps the card closed and focuses the input

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

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
a22aa619f0eef5c7e17c873d8c77a7a845dd7a13
Parent
fc36d5c6
1 file changed +64 −2
crates/app/src/notify/toast.rs +64 −2
@@ -154,6 +154,10 @@ fn flat_button(
154 154 .child(label)
155 155 }
156 156
157 fn keep_clicks_in_toast(area: Stateful<Div>) -> Stateful<Div> {
158 area.on_click(|_, _, cx| cx.stop_propagation())
159 }
160
157 161 fn highlighted_preview(text: &str, mention: bool) -> AnyElement {
158 162 let mut styled = StyledText::new(text.to_owned());
159 163 if mention {
@@ -352,7 +356,7 @@ impl ToastView {
352 356 )
353 357 }
354 358
355 fn reply_field(&self, window: &Window, cx: &mut Context<Self>) -> Div {
359 fn reply_field(&self, window: &Window, cx: &mut Context<Self>) -> Stateful<Div> {
356 360 let focused = self.input.focus_handle(cx).contains_focused(window, cx);
357 361 let empty = self.input.read(cx).value().trim().is_empty();
358 362 let send = div()
@@ -380,7 +384,7 @@ impl ToastView {
380 384 .child(div().text_color(theme::text_soft()).child(keys))
381 385 .child(action)
382 386 };
383 v_flex()
387 keep_clicks_in_toast(v_flex().id("toast-reply-field"))
384 388 .w_full()
385 389 .mt(px(8.))
386 390 .gap(px(4.))
@@ -628,3 +632,61 @@ impl Render for PillView {
628 632 })
629 633 }
630 634 }
635
636 #[cfg(test)]
637 mod tests {
638 use std::cell::Cell;
639 use std::rc::Rc;
640
641 use gpui_kit::component::input::{Textarea, TextareaState};
642 use gpui_kit::{
643 AppContext as _, Context, Entity, Focusable as _, InteractiveElement as _, IntoElement, Modifiers,
644 ParentElement as _, Render, StatefulInteractiveElement as _, Styled as _, TestAppContext,
645 Window, div, point, px,
646 };
647
648 use super::keep_clicks_in_toast;
649
650 struct ToastHarness {
651 input: Entity<TextareaState>,
652 card_clicks: Rc<Cell<usize>>,
653 }
654
655 impl Render for ToastHarness {
656 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
657 let card_clicks = self.card_clicks.clone();
658 div()
659 .id("toast-card")
660 .size_full()
661 .on_click(move |_, _, _| card_clicks.set(card_clicks.get() + 1))
662 .child(
663 keep_clicks_in_toast(div().id("toast-reply-field"))
664 .w(px(300.))
665 .child(Textarea::new(&self.input)),
666 )
667 }
668 }
669
670 #[gpui_kit::test]
671 fn clicking_the_reply_input_does_not_open_the_chat(cx: &mut TestAppContext) {
672 cx.update(gpui_kit::init);
673 let card_clicks = Rc::new(Cell::new(0));
674 let (harness, window_cx) = cx.add_window_view({
675 let card_clicks = card_clicks.clone();
676 move |window, cx| ToastHarness {
677 input: cx.new(|cx| TextareaState::new(window, cx).auto_grow(1, 1)),
678 card_clicks,
679 }
680 });
681 window_cx.update(|window, cx| window.draw(cx).clear(cx));
682 window_cx.simulate_click(point(px(20.), px(12.)), Modifiers::default());
683 assert_eq!(card_clicks.get(), 0);
684 let focused = window_cx.update(|window, cx| {
685 let input = harness.read(cx).input.clone();
686 input.focus_handle(cx).contains_focused(window, cx)
687 });
688 assert!(focused);
689 window_cx.simulate_click(point(px(20.), px(200.)), Modifiers::default());
690 assert_eq!(card_clicks.get(), 1);
691 }
692 }
@@ -154,6 +154,10 @@ fn flat_button(
154 .child(label)
154 .child(label)
155}
155}
156
156
157fn keep_clicks_in_toast(area: Stateful<Div>) -> Stateful<Div> {
158 area.on_click(|_, _, cx| cx.stop_propagation())
159}
160
157fn highlighted_preview(text: &str, mention: bool) -> AnyElement {
161fn highlighted_preview(text: &str, mention: bool) -> AnyElement {
158 let mut styled = StyledText::new(text.to_owned());
162 let mut styled = StyledText::new(text.to_owned());
159 if mention {
163 if mention {
@@ -352,7 +356,7 @@ impl ToastView {
352 )
356 )
353 }
357 }
354
358
355 fn reply_field(&self, window: &Window, cx: &mut Context<Self>) -> Div {
359 fn reply_field(&self, window: &Window, cx: &mut Context<Self>) -> Stateful<Div> {
356 let focused = self.input.focus_handle(cx).contains_focused(window, cx);
360 let focused = self.input.focus_handle(cx).contains_focused(window, cx);
357 let empty = self.input.read(cx).value().trim().is_empty();
361 let empty = self.input.read(cx).value().trim().is_empty();
358 let send = div()
362 let send = div()
@@ -380,7 +384,7 @@ impl ToastView {
380 .child(div().text_color(theme::text_soft()).child(keys))
384 .child(div().text_color(theme::text_soft()).child(keys))
381 .child(action)
385 .child(action)
382 };
386 };
383 v_flex()
387 keep_clicks_in_toast(v_flex().id("toast-reply-field"))
384 .w_full()
388 .w_full()
385 .mt(px(8.))
389 .mt(px(8.))
386 .gap(px(4.))
390 .gap(px(4.))
@@ -628,3 +632,61 @@ impl Render for PillView {
628 })
632 })
629 }
633 }
630}
634}
635
636#[cfg(test)]
637mod tests {
638 use std::cell::Cell;
639 use std::rc::Rc;
640
641 use gpui_kit::component::input::{Textarea, TextareaState};
642 use gpui_kit::{
643 AppContext as _, Context, Entity, Focusable as _, InteractiveElement as _, IntoElement, Modifiers,
644 ParentElement as _, Render, StatefulInteractiveElement as _, Styled as _, TestAppContext,
645 Window, div, point, px,
646 };
647
648 use super::keep_clicks_in_toast;
649
650 struct ToastHarness {
651 input: Entity<TextareaState>,
652 card_clicks: Rc<Cell<usize>>,
653 }
654
655 impl Render for ToastHarness {
656 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
657 let card_clicks = self.card_clicks.clone();
658 div()
659 .id("toast-card")
660 .size_full()
661 .on_click(move |_, _, _| card_clicks.set(card_clicks.get() + 1))
662 .child(
663 keep_clicks_in_toast(div().id("toast-reply-field"))
664 .w(px(300.))
665 .child(Textarea::new(&self.input)),
666 )
667 }
668 }
669
670 #[gpui_kit::test]
671 fn clicking_the_reply_input_does_not_open_the_chat(cx: &mut TestAppContext) {
672 cx.update(gpui_kit::init);
673 let card_clicks = Rc::new(Cell::new(0));
674 let (harness, window_cx) = cx.add_window_view({
675 let card_clicks = card_clicks.clone();
676 move |window, cx| ToastHarness {
677 input: cx.new(|cx| TextareaState::new(window, cx).auto_grow(1, 1)),
678 card_clicks,
679 }
680 });
681 window_cx.update(|window, cx| window.draw(cx).clear(cx));
682 window_cx.simulate_click(point(px(20.), px(12.)), Modifiers::default());
683 assert_eq!(card_clicks.get(), 0);
684 let focused = window_cx.update(|window, cx| {
685 let input = harness.read(cx).input.clone();
686 input.focus_handle(cx).contains_focused(window, cx)
687 });
688 assert!(focused);
689 window_cx.simulate_click(point(px(20.), px(200.)), Modifiers::default());
690 assert_eq!(card_clicks.get(), 1);
691 }
692}