diff --git a/contributors/people.toml b/contributors/people.toml index bc8cf71bb..290681803 100644 --- a/contributors/people.toml +++ b/contributors/people.toml @@ -44,3 +44,7 @@ sync_github_name = true [people.volkovskey] real_name = "Andrii Volkov" + +[people.krinry] +display_name = "krinry" +sync_github_name = true diff --git a/crates/ui-egui/src/panel_remove_tests.rs b/crates/ui-egui/src/panel_remove_tests.rs index 299a4b6f8..ee289bb80 100644 --- a/crates/ui-egui/src/panel_remove_tests.rs +++ b/crates/ui-egui/src/panel_remove_tests.rs @@ -123,3 +123,41 @@ fn removing_effects_and_grids_keeps_open_settings_with_their_rows() { assert_eq!(u.app.session.doc().unwrap().node(f).unwrap().grids.len(), 1); assert!(flag(&u, "grid_open", 0) && !flag(&u, "grid_open", 1)); } + +#[test] +fn adding_a_fill_or_stroke_opens_the_color_picker() { + let mut s = Session::new(); + let r = id(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap()); + s.execute("select.set", &json!({"ids": [r]})).unwrap(); + let mut u = Ui::new(s); + u.ctx.enable_accesskit(); + assert_eq!(u.app.ui.picker, None); + + let out = u.frame_output(vec![]); + let add_fill = out + .platform_output + .accesskit_update + .unwrap() + .nodes + .into_iter() + .find(|(_, n)| n.label() == Some("Add fill")) + .and_then(|(_, n)| n.bounds()) + .map(|b| Pos2::new(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32)) + .expect("Add fill button"); + click(&mut u, add_fill); + assert_eq!(u.app.ui.picker, Some(PickerTarget::Paint { fills: true, index: 1, ids: vec![r] })); + + let out = u.frame_output(vec![]); + let add_stroke = out + .platform_output + .accesskit_update + .unwrap() + .nodes + .into_iter() + .find(|(_, n)| n.label() == Some("Add stroke")) + .and_then(|(_, n)| n.bounds()) + .map(|b| Pos2::new(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32)) + .expect("Add stroke button"); + click(&mut u, add_stroke); + assert_eq!(u.app.ui.picker, Some(PickerTarget::Paint { fills: false, index: 0, ids: vec![r] })); +} diff --git a/crates/ui-egui/src/right.rs b/crates/ui-egui/src/right.rs index 10847896e..5899a949d 100644 --- a/crates/ui-egui/src/right.rs +++ b/crates/ui-egui/src/right.rs @@ -1101,7 +1101,14 @@ fn paints(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId], fills: empty, ) { if i == 1 { - app.run(if fills { "fill.add" } else { "stroke.add" }, json!({"ids": ids})); + if app.run(if fills { "fill.add" } else { "stroke.add" }, json!({"ids": ids})).is_some() { + if let Ok(doc) = app.session.doc() { + let count = ids.first().and_then(|id| doc.node(*id)).map_or(0, |n| if fills { n.fills.len() } else { n.strokes.len() }); + if count > 0 { + app.ui.picker = Some(crate::colorpicker::PickerTarget::Paint { fills, index: count - 1, ids: ids.clone() }); + } + } + } } else { style_picker::open(app, ui, &ids, slot); }