From 9c2d4522b7eea371919e3e2c3090a7355e98f5ed Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 23 Nov 2026 02:34:53 -0500 Subject: [PATCH] fw sync: L-324 comment rows keep upstream's one editor-focus mechanism (EditShown); each card menu opens once per pass (duplicate stage ids) --- crates/review/src/ui/comments.rs | 35 +++++++++++++--------------- crates/review/src/ui/comments/row.rs | 9 ++----- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/crates/review/src/ui/comments.rs b/crates/review/src/ui/comments.rs index 8bb61becb..ad7fdeabc 100644 --- a/crates/review/src/ui/comments.rs +++ b/crates/review/src/ui/comments.rs @@ -130,10 +130,8 @@ pub struct CommentsPanelState { pub search_open: bool, /// The thread the next `show` reveals, once. revealing: Option, - /// The message being edited inline: (thread, message index, text). [`edit`](Self::edit) opens it with the focus. + /// The message being edited inline: (thread, message index, text). [`edit`](Self::edit) opens it. pub editing: Option<(ThreadId, usize, String)>, - /// The inline editor takes the focus the next time its card is built, once. - focus_editor: bool, /// The selected card's reply draft. pub reply: String, /// The "Add a comment" box's draft. @@ -155,12 +153,11 @@ impl CommentsPanelState { self.revealing = Some(thread); } - /// Opens the inline editor on message `index` of `thread` (0: the comment) with `text`, and has the editor take - /// the focus the next time its card is built, once: for an editor the app opens (a new comment's note), as a - /// double click on a card or the message menu's Edit opens one. + /// Opens the inline editor on message `index` of `thread` (0: the comment) with `text`: for an editor the app + /// opens (a new comment's note), as a double click on a card or the message menu's Edit opens one. Like every + /// inline editor, it takes the keyboard in the pass its card first shows it, once. pub fn edit(&mut self, thread: ThreadId, index: usize, text: impl Into) { self.editing = Some((thread, index, text.into())); - self.focus_editor = true; } } @@ -471,7 +468,7 @@ fn toggle(list: &mut Vec, value: T) { /// Makes `next` the selection; true when its threads changed. A new lead drops the reply draft, which belongs to the /// old lead's card, and an edit of another thread; an edit of the new lead itself stays, so a draft the app could not -/// write back (a document that refused it) is there again, with the keyboard, when its card leads again. +/// write back (a document that refused it) is there again when its card leads again. fn set_selection(state: &mut CommentsPanelState, next: Selection) -> bool { let changed = next.items != state.selected.items; if next.lead != state.selected.lead { @@ -480,7 +477,6 @@ fn set_selection(state: &mut CommentsPanelState, next: Selection) -> b if !kept { state.editing = None; } - state.focus_editor = kept; } state.selected = next; changed @@ -680,8 +676,6 @@ impl CommentsPanel<'_, H> { let mut selection = card_selection(&state.selected); let reply: &str = &state.reply; let editing = state.editing.as_ref().map(|(thread, index, text)| (*thread, *index, text.as_str())); - let focus_editor = state.focus_editor; - let mut editor_built = false; let mut openers = Vec::new(); let out = CommentList::new(label.clone(), Some(Bind::bound(&mut selection)), grouped, select_mode) .revealing(revealing.map(CardKey::Thread)) @@ -696,7 +690,6 @@ impl CommentsPanel<'_, H> { .map_or_else(String::new, |first| words.card_name.fill(&[("author", &first.author), ("text", &first.text)])); let is_lead = lead == Some(thread.id); let editing = editing.filter(|(id, ..)| *id == thread.id).map(|(_, index, text)| (index, text)); - editor_built |= editing.is_some(); if is_lead { openers.extend((0..thread.messages.len()).map(|index| (index, item.part_opener(MORE.at(index as u64))))); } @@ -704,19 +697,23 @@ impl CommentsPanel<'_, H> { .state(chosen.contains(&thread.id), !read_only && !thread.locked, now) .lead(is_lead) .focus_reply(is_lead && item.row.activated_by_key) - .focus_editor(focus_editor && editing.is_some()) .submit_key(reply_submit) .drafts(editing, if is_lead { reply } else { "" }) } }); - // The editor's card took the focus request this pass. - if editor_built { - state.focus_editor = false; - } let list = out.response.clone(); let clicks = out.activation_clicks; - let buttons: Vec<(usize, Response)> = - openers.into_iter().filter_map(|(index, opener)| Some((index, out.opener(opener)?.clone()))).collect(); + let mut buttons: Vec<(usize, Response)> = Vec::new(); + // The collection may build the lead's card more than once in a pass: each message's menu opens once, from + // the last build's "..." button, so no two menus share a base id. + for (index, opener) in openers.into_iter().rev() { + if !buttons.iter().any(|(seen, _)| *seen == index) + && let Some(button) = out.opener(opener) + { + buttons.push((index, button.clone())); + } + } + buttons.reverse(); let group_page = |at: usize| match source.entries.iter().find(|(key, _)| *key == CardKey::Group(at)) { Some((_, RowEntry::Group { page, .. })) => *page, _ => None, diff --git a/crates/review/src/ui/comments/row.rs b/crates/review/src/ui/comments/row.rs index 509e90926..393a6ba12 100644 --- a/crates/review/src/ui/comments/row.rs +++ b/crates/review/src/ui/comments/row.rs @@ -197,9 +197,6 @@ pub(crate) struct CommentRow<'r> { /// The activation key reached the card this pass: its reply box takes the focus, when it shows one. #[prop] focus_reply: bool, - /// The inline editor takes the focus this pass, when the card shows one: for an editor the panel opens. - #[prop] - focus_editor: bool, /// The key that submits the reply box. submit_key: SubmitKey, /// The inline editor opened this pass (it did not show the pass before): its field takes the keyboard, so the @@ -239,7 +236,6 @@ impl<'r> CommentRow<'r> { editing: None, reply: "", focus_reply: false, - focus_editor: false, submit_key: SubmitKey::default(), focus_edit: false, actions: CardActions::default(), @@ -914,9 +910,8 @@ impl Component for CommentRow<'_> { badges: &self.badges, reply_submit: self.submit_key, ctx: &cx.ctx, - // The editor the panel opens takes the focus before the reply box, as either opening does. - focus_reply: self.focus_reply && !self.focus_editor, - focus_edit: self.focus_edit || self.focus_editor, + focus_reply: self.focus_reply, + focus_edit: self.focus_edit, reply_id: None, events: &mut events, };