BlueGit

ict rusty-teams

fix(chat): group name field keeps its text and takes space and enter

- keep the form across renders instead of rebuilding it every frame (hang)
- popover: enter and space toggle only from the trigger, not from its content

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-10 · 3 weeks ago

Hash
71351a467c122c7e2c673ed36272b8f55bab2138
Parent
9a1b6f9d
4 files changed +50 −5
crates/app/src/layout_guard.rs +31 −0
@@ -198,6 +198,7 @@ mod frames {
198 198 FEED_EDGE_TAG, FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG,
199 199 FORWARD_FOOTER_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG,
200 200 };
201 use crate::views::group_name::{GROUP_NAME_BUTTON, GROUP_NAME_FORM};
201 202 use crate::views::post_card::{
202 203 POST_AVATAR_TAG, POST_BODY_TAG, POST_CARD_TAG, POST_FOOTER_AVATAR_TAG,
203 204 };
@@ -1583,6 +1584,36 @@ mod frames {
1583 1584 }
1584 1585 }
1585 1586
1587 #[gpui_kit::test]
1588 fn the_group_name_field_keeps_typed_text_across_frames(cx: &mut TestAppContext) {
1589 let (handle, state) = mount(cx);
1590 let mut visual = VisualTestContext::from_window(handle, cx);
1591 visual.update(|_, cx| {
1592 state.update(cx, |state, cx| {
1593 state.select(Selection::Chat(MEMBERS_CHAT.to_owned()), cx)
1594 })
1595 });
1596 collect(&mut visual, Some(GROUP_NAME_BUTTON));
1597 let button = visual
1598 .debug_bounds(GROUP_NAME_BUTTON)
1599 .expect("group name button rendered");
1600 visual.simulate_click(button.center(), Default::default());
1601 collect(&mut visual, Some(GROUP_NAME_FORM));
1602 assert!(visual.debug_bounds(GROUP_NAME_FORM).is_some(), "group name form open");
1603 visual.simulate_keystrokes("backspace x space y enter");
1604 visual.run_until_parked();
1605 let title = visual.update(|_, cx| {
1606 state
1607 .read(cx)
1608 .sidebar
1609 .chats
1610 .iter()
1611 .find(|chat| chat.id == MEMBERS_CHAT)
1612 .map(|chat| chat.title.clone())
1613 });
1614 assert_eq!(title.as_deref(), Some("Release planninx y"));
1615 }
1616
1586 1617 const FORWARD_CHAT: &str = "demo-chat-release";
1587 1618 const FORWARD_FOOTER_TAGS: [&str; 4] = [
1588 1619 FORWARD_FOOTER_TAG,
@@ -198,6 +198,7 @@ mod frames {
198 FEED_EDGE_TAG, FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG,
198 FEED_EDGE_TAG, FORWARD_FOOTER_BAR_TAG, FORWARD_FOOTER_COUNT_TAG, FORWARD_FOOTER_NEXT_TAG,
199 FORWARD_FOOTER_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG,
199 FORWARD_FOOTER_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG,
200 };
200 };
201 use crate::views::group_name::{GROUP_NAME_BUTTON, GROUP_NAME_FORM};
201 use crate::views::post_card::{
202 use crate::views::post_card::{
202 POST_AVATAR_TAG, POST_BODY_TAG, POST_CARD_TAG, POST_FOOTER_AVATAR_TAG,
203 POST_AVATAR_TAG, POST_BODY_TAG, POST_CARD_TAG, POST_FOOTER_AVATAR_TAG,
203 };
204 };
@@ -1583,6 +1584,36 @@ mod frames {
1583 }
1584 }
1584 }
1585 }
1585
1586
1587 #[gpui_kit::test]
1588 fn the_group_name_field_keeps_typed_text_across_frames(cx: &mut TestAppContext) {
1589 let (handle, state) = mount(cx);
1590 let mut visual = VisualTestContext::from_window(handle, cx);
1591 visual.update(|_, cx| {
1592 state.update(cx, |state, cx| {
1593 state.select(Selection::Chat(MEMBERS_CHAT.to_owned()), cx)
1594 })
1595 });
1596 collect(&mut visual, Some(GROUP_NAME_BUTTON));
1597 let button = visual
1598 .debug_bounds(GROUP_NAME_BUTTON)
1599 .expect("group name button rendered");
1600 visual.simulate_click(button.center(), Default::default());
1601 collect(&mut visual, Some(GROUP_NAME_FORM));
1602 assert!(visual.debug_bounds(GROUP_NAME_FORM).is_some(), "group name form open");
1603 visual.simulate_keystrokes("backspace x space y enter");
1604 visual.run_until_parked();
1605 let title = visual.update(|_, cx| {
1606 state
1607 .read(cx)
1608 .sidebar
1609 .chats
1610 .iter()
1611 .find(|chat| chat.id == MEMBERS_CHAT)
1612 .map(|chat| chat.title.clone())
1613 });
1614 assert_eq!(title.as_deref(), Some("Release planninx y"));
1615 }
1616
1586 const FORWARD_CHAT: &str = "demo-chat-release";
1617 const FORWARD_CHAT: &str = "demo-chat-release";
1587 const FORWARD_FOOTER_TAGS: [&str; 4] = [
1618 const FORWARD_FOOTER_TAGS: [&str; 4] = [
1588 FORWARD_FOOTER_TAG,
1619 FORWARD_FOOTER_TAG,
crates/app/src/views/conversation.rs +4 −2
@@ -57,7 +57,7 @@ use super::chat_members::members_popover;
57 57 use super::chat_pop_out;
58 58 use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};
59 59 use super::find_panel::{FIND_PANEL_WIDTH, FindPanel, FindPanelEvent};
60 use super::group_name::group_name_button;
60 use super::group_name::{GroupNameSlot, group_name_button};
61 61 use super::message_actions::{Action, DelegateEntry, MessageMenu};
62 62 use super::message_row::{
63 63 AVATAR_GAP, AVATAR_SIZE, JUMP_HIGHLIGHT_PERIOD, render_message_row, render_skeleton_row,
@@ -278,6 +278,7 @@ pub struct ConversationView {
278 278 receipt_fade: receipt_fade::ReceiptFade,
279 279 find_panel: Option<Entity<FindPanel>>,
280 280 find_subscription: Option<Subscription>,
281 group_name: GroupNameSlot,
281 282 _subscriptions: Vec<Subscription>,
282 283 }
283 284
@@ -564,6 +565,7 @@ impl ConversationView {
564 565 subscriptions.push(cx.observe(&api, |this, _, cx| this.sync_reaction_pills(cx)));
565 566 }
566 567 let mut view = ConversationView {
568 group_name: GroupNameSlot::default(),
567 569 app,
568 570 pinned: pinned.is_some(),
569 571 popped_out: false,
@@ -3710,7 +3712,7 @@ impl ConversationView {
3710 3712 .any(|member| member.user_id.as_deref() == Some(&me.user_id))
3711 3713 })
3712 3714 {
3713 rename = Some(group_name_button(&self.app, chat_id, &chat.title));
3715 rename = Some(group_name_button(&self.app, &self.group_name, chat_id, &chat.title));
3714 3716 }
3715 3717 if chat.title.trim().is_empty() {
3716 3718 names_title = Some(chat_header_actions::group_title(directory, &faces));
@@ -57,7 +57,7 @@ use super::chat_members::members_popover;
57use super::chat_pop_out;
57use super::chat_pop_out;
58use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};
58use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};
59use super::find_panel::{FIND_PANEL_WIDTH, FindPanel, FindPanelEvent};
59use super::find_panel::{FIND_PANEL_WIDTH, FindPanel, FindPanelEvent};
60use super::group_name::group_name_button;
60use super::group_name::{GroupNameSlot, group_name_button};
61use super::message_actions::{Action, DelegateEntry, MessageMenu};
61use super::message_actions::{Action, DelegateEntry, MessageMenu};
62use super::message_row::{
62use super::message_row::{
63 AVATAR_GAP, AVATAR_SIZE, JUMP_HIGHLIGHT_PERIOD, render_message_row, render_skeleton_row,
63 AVATAR_GAP, AVATAR_SIZE, JUMP_HIGHLIGHT_PERIOD, render_message_row, render_skeleton_row,
@@ -278,6 +278,7 @@ pub struct ConversationView {
278 receipt_fade: receipt_fade::ReceiptFade,
278 receipt_fade: receipt_fade::ReceiptFade,
279 find_panel: Option<Entity<FindPanel>>,
279 find_panel: Option<Entity<FindPanel>>,
280 find_subscription: Option<Subscription>,
280 find_subscription: Option<Subscription>,
281 group_name: GroupNameSlot,
281 _subscriptions: Vec<Subscription>,
282 _subscriptions: Vec<Subscription>,
282}
283}
283
284
@@ -564,6 +565,7 @@ impl ConversationView {
564 subscriptions.push(cx.observe(&api, |this, _, cx| this.sync_reaction_pills(cx)));
565 subscriptions.push(cx.observe(&api, |this, _, cx| this.sync_reaction_pills(cx)));
565 }
566 }
566 let mut view = ConversationView {
567 let mut view = ConversationView {
568 group_name: GroupNameSlot::default(),
567 app,
569 app,
568 pinned: pinned.is_some(),
570 pinned: pinned.is_some(),
569 popped_out: false,
571 popped_out: false,
@@ -3710,7 +3712,7 @@ impl ConversationView {
3710 .any(|member| member.user_id.as_deref() == Some(&me.user_id))
3712 .any(|member| member.user_id.as_deref() == Some(&me.user_id))
3711 })
3713 })
3712 {
3714 {
3713 rename = Some(group_name_button(&self.app, chat_id, &chat.title));
3715 rename = Some(group_name_button(&self.app, &self.group_name, chat_id, &chat.title));
3714 }
3716 }
3715 if chat.title.trim().is_empty() {
3717 if chat.title.trim().is_empty() {
3716 names_title = Some(chat_header_actions::group_title(directory, &faces));
3718 names_title = Some(chat_header_actions::group_title(directory, &faces));
crates/app/src/views/group_name.rs +11 −3
@@ -15,6 +15,8 @@ use super::widgets::icon;
15 15 use crate::app_state::AppState;
16 16 use crate::theme;
17 17
18 pub const GROUP_NAME_FORM: &str = "shell/islands/main/group-name-form";
19 pub const GROUP_NAME_BUTTON: &str = "shell/islands/main/group-name-button";
18 20 const BUTTON_TOOLTIP: &str = "Name group chat";
19 21 const FIELD_LABEL: &str = "Group name";
20 22 const PLACEHOLDER: &str = "Type a group name";
@@ -108,6 +110,7 @@ impl Render for GroupNameForm {
108 110 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
109 111 let problem = self.problem(cx);
110 112 v_flex()
113 .debug_selector(|| GROUP_NAME_FORM.into())
111 114 .w(px(FORM_WIDTH))
112 115 .p(px(FORM_PADDING))
113 116 .gap(px(FORM_GAP))
@@ -146,9 +149,12 @@ impl Render for GroupNameForm {
146 149 }
147 150 }
148 151
149 pub fn group_name_button(app: &Entity<AppState>, chat_id: &str, title: &str) -> AnyElement {
152 #[derive(Clone, Default)]
153 pub struct GroupNameSlot(Rc<RefCell<Option<Entity<GroupNameForm>>>>);
154
155 pub fn group_name_button(app: &Entity<AppState>, slot: &GroupNameSlot, chat_id: &str, title: &str) -> AnyElement {
150 156 let (app, chat_id, title) = (app.clone(), chat_id.to_owned(), title.to_owned());
151 let form: Rc<RefCell<Option<Entity<GroupNameForm>>>> = Rc::default();
157 let form = slot.0.clone();
152 158 let reset = form.clone();
153 159 Popover::new("group-name")
154 160 .anchor(Anchor::TopLeft)
@@ -158,6 +164,7 @@ pub fn group_name_button(app: &Entity<AppState>, chat_id: &str, title: &str) ->
158 164 .ghost()
159 165 .compact()
160 166 .tooltip(BUTTON_TOOLTIP)
167 .debug_selector(|| GROUP_NAME_BUTTON.into())
161 168 .child(icon(IconName::Pencil, ICON_SIZE, theme::text_soft())),
162 169 )
163 170 .on_open_change(move |open, _, _| {
@@ -166,7 +173,8 @@ pub fn group_name_button(app: &Entity<AppState>, chat_id: &str, title: &str) ->
166 173 }
167 174 })
168 175 .content(move |_, window, cx| {
169 if let Some(existing) = form.borrow().clone() {
176 let existing = form.borrow().clone();
177 if let Some(existing) = existing.filter(|existing| existing.read(cx).chat_id == chat_id) {
170 178 return existing;
171 179 }
172 180 let popover = cx.entity().downgrade();
@@ -15,6 +15,8 @@ use super::widgets::icon;
15use crate::app_state::AppState;
15use crate::app_state::AppState;
16use crate::theme;
16use crate::theme;
17
17
18pub const GROUP_NAME_FORM: &str = "shell/islands/main/group-name-form";
19pub const GROUP_NAME_BUTTON: &str = "shell/islands/main/group-name-button";
18const BUTTON_TOOLTIP: &str = "Name group chat";
20const BUTTON_TOOLTIP: &str = "Name group chat";
19const FIELD_LABEL: &str = "Group name";
21const FIELD_LABEL: &str = "Group name";
20const PLACEHOLDER: &str = "Type a group name";
22const PLACEHOLDER: &str = "Type a group name";
@@ -108,6 +110,7 @@ impl Render for GroupNameForm {
108 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
110 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
109 let problem = self.problem(cx);
111 let problem = self.problem(cx);
110 v_flex()
112 v_flex()
113 .debug_selector(|| GROUP_NAME_FORM.into())
111 .w(px(FORM_WIDTH))
114 .w(px(FORM_WIDTH))
112 .p(px(FORM_PADDING))
115 .p(px(FORM_PADDING))
113 .gap(px(FORM_GAP))
116 .gap(px(FORM_GAP))
@@ -146,9 +149,12 @@ impl Render for GroupNameForm {
146 }
149 }
147}
150}
148
151
149pub fn group_name_button(app: &Entity<AppState>, chat_id: &str, title: &str) -> AnyElement {
152#[derive(Clone, Default)]
153pub struct GroupNameSlot(Rc<RefCell<Option<Entity<GroupNameForm>>>>);
154
155pub fn group_name_button(app: &Entity<AppState>, slot: &GroupNameSlot, chat_id: &str, title: &str) -> AnyElement {
150 let (app, chat_id, title) = (app.clone(), chat_id.to_owned(), title.to_owned());
156 let (app, chat_id, title) = (app.clone(), chat_id.to_owned(), title.to_owned());
151 let form: Rc<RefCell<Option<Entity<GroupNameForm>>>> = Rc::default();
157 let form = slot.0.clone();
152 let reset = form.clone();
158 let reset = form.clone();
153 Popover::new("group-name")
159 Popover::new("group-name")
154 .anchor(Anchor::TopLeft)
160 .anchor(Anchor::TopLeft)
@@ -158,6 +164,7 @@ pub fn group_name_button(app: &Entity<AppState>, chat_id: &str, title: &str) ->
158 .ghost()
164 .ghost()
159 .compact()
165 .compact()
160 .tooltip(BUTTON_TOOLTIP)
166 .tooltip(BUTTON_TOOLTIP)
167 .debug_selector(|| GROUP_NAME_BUTTON.into())
161 .child(icon(IconName::Pencil, ICON_SIZE, theme::text_soft())),
168 .child(icon(IconName::Pencil, ICON_SIZE, theme::text_soft())),
162 )
169 )
163 .on_open_change(move |open, _, _| {
170 .on_open_change(move |open, _, _| {
@@ -166,7 +173,8 @@ pub fn group_name_button(app: &Entity<AppState>, chat_id: &str, title: &str) ->
166 }
173 }
167 })
174 })
168 .content(move |_, window, cx| {
175 .content(move |_, window, cx| {
169 if let Some(existing) = form.borrow().clone() {
176 let existing = form.borrow().clone();
177 if let Some(existing) = existing.filter(|existing| existing.read(cx).chat_id == chat_id) {
170 return existing;
178 return existing;
171 }
179 }
172 let popover = cx.entity().downgrade();
180 let popover = cx.entity().downgrade();
vendor/gpui-base/src/popover.rs +4 −0
@@ -328,6 +328,10 @@ impl RenderOnce for Popover {
328 328 .on_action({
329 329 let state = state.clone();
330 330 move |_: &Confirm, window, cx| {
331 if state.read(cx).focus_handle.contains_focused(window, cx) {
332 cx.propagate();
333 return;
334 }
331 335 state.update(cx, |state, cx| state.toggle_open(window, cx));
332 336 cx.notify(parent_view_id);
333 337 }
@@ -328,6 +328,10 @@ impl RenderOnce for Popover {
328 .on_action({
328 .on_action({
329 let state = state.clone();
329 let state = state.clone();
330 move |_: &Confirm, window, cx| {
330 move |_: &Confirm, window, cx| {
331 if state.read(cx).focus_handle.contains_focused(window, cx) {
332 cx.propagate();
333 return;
334 }
331 state.update(cx, |state, cx| state.toggle_open(window, cx));
335 state.update(cx, |state, cx| state.toggle_open(window, cx));
332 cx.notify(parent_view_id);
336 cx.notify(parent_view_id);
333 }
337 }