diff --git a/crates/ui-egui/src/dialogs/color_picker_ui.rs b/crates/ui-egui/src/dialogs/color_picker_ui.rs index ec1f6bc8cd2..3723900a9d0 100644 --- a/crates/ui-egui/src/dialogs/color_picker_ui.rs +++ b/crates/ui-egui/src/dialogs/color_picker_ui.rs @@ -424,6 +424,14 @@ fn commit(app: &mut PhotocraftApp, _id: DialogId, target: PickTarget, picked: &P PickTarget::NewSolidFill { document } => crate::solid_fill_ui::confirm_new(app, *document, picked), PickTarget::Request { parent, key } => { if let Some(dialog) = app.framework.dialogs.get_mut_by_id::(*parent) { + // The colour goes in with its inks at once, so an OK of the parent right after this one (an agent's next + // request, before a dialog pass has taken the answer) fills with it; a row with opacity keeps its own. + let [r, g, b] = picked.color.to_rgb_array(); + let value = match dialog.fields().get(key) { + Some(FieldValue::Rgba([.., a])) => FieldValue::Rgba([r, g, b, *a]), + _ => FieldValue::Color([r, g, b]), + }; + dialog.set_field(key.clone(), value); dialog.set_field(ink_field(key), ink_value(picked.color, inks_of(picked))); } app.color_answers.push((*parent, key.clone(), picked.color)); diff --git a/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs b/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs index 3ef20bddab7..6f32ae7ff31 100644 --- a/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs +++ b/crates/ui-egui/src/dialogs/fill_ui/color_entry_tests.rs @@ -163,3 +163,18 @@ fn picker_cancel_from_foreground_fills_with_the_remembered_colour() { let [r, g, b, _] = pixel(&h); assert!(close([r, g, b], rgb(BLUE)), "Fill OK fills with the remembered colour: {:?}", pixel(&h)); } + +/// Fill OK straight after picker OK, with no dialog pass between them (an agent's two requests), fills with the picked +/// colour: the picker writes it into Fill at once. +#[test] +fn fill_ok_right_after_picker_ok_fills_with_the_picked_colour() { + let mut h = harness(); + let fill = open_fill(&mut h); + let id = choose_color(&mut h).expect("the picker opens"); + picker::set_color(h.state_mut(), id, GREEN); + confirm(h.state_mut(), id).unwrap(); + confirm(h.state_mut(), fill).unwrap(); + h.run_steps(3); + let [r, g, b, _] = pixel(&h); + assert!(close([r, g, b], rgb(GREEN)), "Fill OK fills with the picked colour: {:?}", pixel(&h)); +}