From baaa53c8019fdce11bda9cca50a3fa8a74f8a83d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 21:04:25 -0500 Subject: [PATCH] Comments: an edit's button reads Save, a new comment's Post (trials) --- crates/review/src/ui/comments.rs | 1 + crates/review/src/ui/comments/row.rs | 4 ++-- crates/review/src/ui/thread.rs | 1 + crates/review/src/ui/thread/popover.rs | 4 +++- crates/review/tests/it/comments.rs | 1 + crates/review/tests/it/note_popup.rs | 16 +++++++++++++++- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/review/src/ui/comments.rs b/crates/review/src/ui/comments.rs index e7a8b6681..620e26d37 100644 --- a/crates/review/src/ui/comments.rs +++ b/crates/review/src/ui/comments.rs @@ -65,6 +65,7 @@ craft_ui::words! { add_comment: "comments.add" = "Add a comment"; reply: "comments.reply" = "Add a reply"; post: "comments.post" = "Post"; + save: "comments.save" = "Save"; cancel: "comments.cancel" = "Cancel"; more: "comments.more" = "More"; edit: "comments.edit" = "Edit"; diff --git a/crates/review/src/ui/comments/row.rs b/crates/review/src/ui/comments/row.rs index c5d3c5882..ec4857a37 100644 --- a/crates/review/src/ui/comments/row.rs +++ b/crates/review/src/ui/comments/row.rs @@ -413,11 +413,11 @@ impl CommentRow<'_> { Some((editing, draft)) if editing == index => { let field = sink.field(Slot::EditField, strip(at, room), &words.edit, draft, EDIT_LINES); let y = at.y + field + st.gap; - let (post_size, cancel_size) = (sink.push_size(Slot::EditPost, &words.post), sink.push_size(Slot::EditCancel, &words.cancel)); + let (post_size, cancel_size) = (sink.push_size(Slot::EditPost, &words.save), sink.push_size(Slot::EditCancel, &words.cancel)); let right = at.x + room; let cancel = Rect::from_min_size(Pos2::new(right - cancel_size.x, y), cancel_size); let post = Rect::from_min_size(Pos2::new(cancel.left() - st.gap - post_size.x, y), post_size); - sink.push(Slot::EditPost, post, &words.post, !draft.trim().is_empty()); + sink.push(Slot::EditPost, post, &words.save, !draft.trim().is_empty()); sink.push(Slot::EditCancel, cancel, &words.cancel, true); y + post_size.y.max(cancel_size.y) } diff --git a/crates/review/src/ui/thread.rs b/crates/review/src/ui/thread.rs index ab7fd4848..34bfca8f0 100644 --- a/crates/review/src/ui/thread.rs +++ b/crates/review/src/ui/thread.rs @@ -24,6 +24,7 @@ craft_ui::words! { reply: "thread.reply" = "Reply"; add_comment: "thread.addComment" = "Add a comment"; post: "thread.post" = "Post"; + save: "thread.save" = "Save"; edit: "thread.edit" = "Edit"; delete: "thread.delete" = "Delete"; delete_thread: "thread.deleteThread" = "Delete thread"; diff --git a/crates/review/src/ui/thread/popover.rs b/crates/review/src/ui/thread/popover.rs index 122cd1d20..88571bade 100644 --- a/crates/review/src/ui/thread/popover.rs +++ b/crates/review/src/ui/thread/popover.rs @@ -367,7 +367,9 @@ impl CommentComposer<'_> { posted.clone_from(&text); } Row::new().show(ui, |ui, _| { - let post = Button::new(words.post.clone()).enabled(text.is_some()).show(ui); + // An edit saves; a new comment posts. + let word = if kind == ComposerDraft::New { &words.post } else { &words.save }; + let post = Button::new(word.clone()).enabled(text.is_some()).show(ui); if clicked(&post) && text.is_some() { posted.clone_from(&text); } diff --git a/crates/review/tests/it/comments.rs b/crates/review/tests/it/comments.rs index 52ad58e17..c6bcc6c3d 100644 --- a/crates/review/tests/it/comments.rs +++ b/crates/review/tests/it/comments.rs @@ -284,6 +284,7 @@ fn a_heading_folds_its_page_and_a_double_click_edits_a_card() { let note = card(&fixture, "Note 2.").expect("card 2").center(); fixture.click_at(note).click_at(note).settle(); assert_eq!(state.borrow().editing, Some((ThreadId(2), 0, "Note 2.".to_owned())), "the double click opens the comment's editor"); + assert!(fixture.by_label("Save").is_some(), "the editor's button is Save, as production's"); } /// The Own header draws its Sort, filter and Pages buttons and the Hosted one none; the host's rows follow a diff --git a/crates/review/tests/it/note_popup.rs b/crates/review/tests/it/note_popup.rs index e419bd44a..548827188 100644 --- a/crates/review/tests/it/note_popup.rs +++ b/crates/review/tests/it/note_popup.rs @@ -3,7 +3,7 @@ use std::cell::{Cell, RefCell}; use std::rc::Rc; -use craft_review::ui::{CommentComposer, ComposerClose, NOTE_POPUP_LIMITS, NoteDrafts, NotePopup, NotePopupMessage}; +use craft_review::ui::{CommentComposer, ComposerClose, ComposerDraft, NOTE_POPUP_LIMITS, NoteDrafts, NotePopup, NotePopupMessage}; use craft_ui::buttons::Button; use craft_ui::contract::Show as _; use craft_ui::contract::overlay::PlacementKind; @@ -309,3 +309,17 @@ fn the_title_band_runs_under_the_close_control() { let widest = bands.iter().map(|r| r.width()).fold(0.0, f32::max); assert!((widest - rect.width()).abs() < 1.5, "the band covers the window's width, close control included: {bands:?}"); } + +/// A composer that edits an existing comment saves it; one that starts a comment posts it. +#[trial] +fn an_edit_composer_reads_save_and_a_new_one_reads_post() { + for (kind, word, other) in [(ComposerDraft::New, "Post", "Save"), (ComposerDraft::Edit, "Save", "Post")] { + let mut draft = String::from("text"); + let mut fixture = Fixture::new(move |ui| { + let _ = CommentComposer::new(Some(pos2(200.0, 200.0)), &mut draft).draft_kind(kind).show(ui); + }); + fixture.room(vec2(800.0, 600.0)).settle(); + assert!(fixture.by_label(word).is_some(), "{kind:?}: the button reads {word}"); + assert!(fixture.by_label(other).is_none(), "{kind:?}: not {other}"); + } +}