Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Replace Color: the sample eyedropper is armed when the dialog opens (#6279)

itsF4LCON425808971613
diff --git a/crates/ui-egui/src/filter_dialog.rs b/crates/ui-egui/src/filter_dialog.rs
index fa7cb9524..83944a1b0 100644
--- a/crates/ui-egui/src/filter_dialog.rs
+++ b/crates/ui-egui/src/filter_dialog.rs
@@ -388,6 +388,11 @@ fn apply_command_defaults(app: &PhotocraftApp, command: &str, fields: &mut Map<S
if command == "edit.assignProfile" {
assign_profile_defaults(app, fields);
}
+ // Photoshop's Replace Color opens with its sample eyedropper active (#6279): the first click
+ // on the image picks the colour.
+ if command == REPLACE_COLOR {
+ fields.insert(COLOR_EYEDROPPER.into(), json!(true));
+ }
}
/// Assign Profile offers only the profiles the document's colour mode can take (#4951): the
@@ -2345,8 +2350,7 @@ mod tests {
app.run("tools.setColors", json!({"foreground": "#ff0000"})).unwrap();
let id = open(&mut app, REPLACE_COLOR).unwrap();
assert_eq!(app.ui.dialogs.last().unwrap().fields["color"], json!("#ff0000"), "the dialog starts from the foreground colour");
- assert!(!color_eyedropper_armed(&app));
- app.ui.dialog_mut(id).unwrap().fields.insert(COLOR_EYEDROPPER.into(), json!(true));
+ // #6279: armed as it opens, so the first click on the image samples.
assert!(color_eyedropper_armed(&app));
assert!(color_eyedropper_sample(&mut app, 4.0, 4.0));
assert_eq!(app.ui.dialogs.last().unwrap().fields["color"], json!("#00ff00"));
@@ -2362,7 +2366,7 @@ mod tests {
assert!(!color_eyedropper_sample(&mut app, 4.0, 4.0));
}
- /// #4143: the eyedropper button arms and disarms the canvas picker.
+ /// #4143: the eyedropper button disarms and re-arms the canvas picker (#6279: it opens armed).
#[test]
fn replace_color_dialog_arms_the_eyedropper_button() {
use egui_kittest::Harness;
@@ -2375,12 +2379,13 @@ mod tests {
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
open(h.state_mut(), REPLACE_COLOR).unwrap();
h.run_steps(3);
+ assert!(color_eyedropper_armed(h.state()), "armed as the dialog opens");
h.get_by_label("Pick Color From Image").click();
h.run_steps(2);
- assert!(color_eyedropper_armed(h.state()));
+ assert!(!color_eyedropper_armed(h.state()));
h.get_by_label("Pick Color From Image").click();
h.run_steps(2);
- assert!(!color_eyedropper_armed(h.state()));
+ assert!(color_eyedropper_armed(h.state()));
}
/// #4457: Localized Color Clusters and its Range, as in Photoshop's dialog; the sampled point