M1: pop up colour picker when adding a fill or stroke (#404)

Clicking the + button to add a fill or stroke in the Design panel now
immediately opens the colour picker dialog for the newly added paint,
matching Figma's behaviour.
This commit is contained in:
krinry
2026-10-16 06:45:40 +05:30
parent f40c600e67
commit b525fde8d1
3 changed files with 50 additions and 1 deletions
+4
View File
@@ -44,3 +44,7 @@ sync_github_name = true
[people.volkovskey]
real_name = "Andrii Volkov"
[people.krinry]
display_name = "krinry"
sync_github_name = true
+38
View File
@@ -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] }));
}
+8 -1
View File
@@ -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);
}