From 0f54b38f4218512d55b1fb0983500b4d6bff347a Mon Sep 17 00:00:00 2001 From: Denis Gomes <6731020+denisg0mes@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:51:49 -0500 Subject: [PATCH] M3: A variable created with a group shown goes into that group With a group selected in the Local variables window, + Create variable named the new variable after its type alone ("Number"), so it went to the collection's top level. The table, showing the group, didn't show it; only All variables did. In Figma it's made in the group shown. Duplicate already kept the group (the copy is "space/sm copy"). The new variable's name now starts with the group shown. Its name opens for editing right away, and the row's field edited the whole name while the row shows only the last part, so typing a name over the new grouped variable would have moved it straight back out of the group. The field now edits the part shown and keeps the group; the Edit variable window still edits the whole name, which is where a variable moves between groups by typing. A name typed there with nothing but slashes and spaces is ignored, as an empty one is: under the group it would clean up to the group's own name and drop the variable out of it. Creating a collection clears the group shown, as picking another collection does, so its first variable isn't named after a group of the collection shown before. --- crates/ui-egui/src/dialogs/variables_panel.rs | 11 +- crates/ui-egui/src/lib.rs | 2 + .../src/variables_group_create_tests.rs | 127 ++++++++++++++++++ docs/components-parity.md | 5 +- 4 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/variables_group_create_tests.rs diff --git a/crates/ui-egui/src/dialogs/variables_panel.rs b/crates/ui-egui/src/dialogs/variables_panel.rs index 961471cd0..55bb0cdc2 100644 --- a/crates/ui-egui/src/dialogs/variables_panel.rs +++ b/crates/ui-egui/src/dialogs/variables_panel.rs @@ -683,6 +683,7 @@ fn create_collection(app: &mut FigApp, vars: &Variables, st: &mut Editor) { { st.library = None; st.collection = Some(id.clone()); + st.group = None; start_rename(st, Rename::Collection(id)); } } @@ -896,7 +897,11 @@ fn var_row(app: &mut FigApp, ui: &mut Ui, view: &View, coll: &Collection, v: &Va // An inherited variable is named (and deleted) in the collection it extends. let inherited = v.extends.is_some(); if editable && st.rename.as_ref() == Some(&target) { - if let Some(name) = rename_field(ui, st, &target, &v.name, name_r, regular(11.0)) { + // The row shows the name's last part: the field edits that and keeps the group. A name of + // slashes and spaces alone is ignored, as the group would swallow it and drop the variable. + let (group, short) = v.name.rsplit_once('/').unwrap_or(("", &v.name)); + if let Some(typed) = rename_field(ui, st, &target, short, name_r, regular(11.0)).filter(|n| n.split('/').any(|p| !p.trim().is_empty())) { + let name = if group.is_empty() { typed } else { format!("{group}/{typed}") }; app.run("variable.update", json!({"variable": v.id, "name": name})); } } else { @@ -1160,7 +1165,9 @@ fn create_row(app: &mut FigApp, ui: &mut Ui, view: &View, coll: &Collection, st: VariableType::Boolean => tr_noop("Boolean"), }; if menu_item(ui, tr(label), "") { - let name = unique(label, |n| view.in_collection(&coll.id).any(|v| v.name == n)); + // Made in the group shown, so the table showing it lists it. + let base = st.group.as_ref().map_or_else(|| label.to_string(), |g| format!("{g}/{label}")); + let name = unique(&base, |n| view.in_collection(&coll.id).any(|v| v.name == n)); let params = json!({"collection": coll.id, "name": name, "type": kind.id()}); if let Some(id) = app.run("variable.create", params).and_then(|r| r["id"].as_str().map(str::to_string)) { st.query.clear(); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 32d859f6c..d3b4ad05b 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -300,6 +300,8 @@ mod variable_picker_tests; #[cfg(test)] mod variables_export_ui_tests; #[cfg(test)] +mod variables_group_create_tests; +#[cfg(test)] mod variables_rename_tests; #[cfg(test)] mod variables_select_tests; diff --git a/crates/ui-egui/src/variables_group_create_tests.rs b/crates/ui-egui/src/variables_group_create_tests.rs new file mode 100644 index 000000000..81ed67ef7 --- /dev/null +++ b/crates/ui-egui/src/variables_group_create_tests.rs @@ -0,0 +1,127 @@ +//! Variables made and named with a group shown in the Local variables window: Create variable +//! and Duplicate put the variable in that group, and renaming it in its row edits the part shown. +use egui::{Event, Key, Modifiers, PointerButton, Pos2}; +use figcraft_engine::Session; +use serde_json::json; + +use crate::layers_drag_tests::Ui; +use crate::live_tests::{flat, has_text, text_center, texts}; + +fn window_with_groups() -> Ui { + let mut s = Session::new(); + s.execute("variable.createCollection", &json!({"name": "Theme"})).unwrap(); + for n in ["space/sm", "color/brand"] { + s.execute("variable.create", &json!({"collection": "Theme", "name": n, "type": "number", "value": 1})).unwrap(); + } + let mut u = Ui::new(s); + u.app.ui.variables = Some(Default::default()); + settle(&mut u); + u +} + +fn settle(u: &mut Ui) { + for _ in 0..8 { + u.frame(vec![]); + } +} + +fn click(u: &mut Ui, p: Pos2, button: PointerButton) { + for pressed in [true, false] { + u.frame(vec![Event::PointerMoved(p), Event::PointerButton { pos: p, button, pressed, modifiers: Modifiers::NONE }]); + } + settle(u); +} + +fn leftmost(u: &mut Ui, s: &str) -> Pos2 { + let shapes = flat(&u.frame_output(vec![]).shapes); + let (_, at, size) = + texts(&shapes).into_iter().filter(|(t, ..)| t == s).min_by(|a, b| a.1.x.total_cmp(&b.1.x)).unwrap_or_else(|| panic!("{s} drawn")); + at + size / 2.0 +} + +fn names(u: &Ui) -> Vec { + let mut v: Vec = u.app.session.doc().unwrap().variables.variables.iter().map(|v| v.name.clone()).collect(); + v.sort(); + v +} + +fn shown(u: &mut Ui, s: &str) -> bool { + has_text(&flat(&u.frame_output(vec![]).shapes), s) +} + +#[test] +fn a_variable_created_with_a_group_shown_goes_into_that_group_and_keeps_it_when_named() { + let mut u = window_with_groups(); + let group = leftmost(&mut u, "space"); + click(&mut u, group, PointerButton::Primary); + assert!(!shown(&mut u, "brand"), "only the space group is shown"); + + let create = text_center(&flat(&u.frame_output(vec![]).shapes), "+ Create variable"); + click(&mut u, create, PointerButton::Primary); + let number = text_center(&flat(&u.frame_output(vec![]).shapes), "Number"); + click(&mut u, number, PointerButton::Primary); + assert_eq!(names(&u), ["color/brand", "space/Number", "space/sm"]); + + u.frame(vec![Event::Text("lg".into())]); + for pressed in [true, false] { + u.frame(vec![Event::Key { key: Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }]); + } + settle(&mut u); + assert_eq!(names(&u), ["color/brand", "space/lg", "space/sm"], "naming it in its row keeps the group"); + assert!(shown(&mut u, "lg"), "and it is in the table shown"); + assert!(u.app.ui.last_error.is_none(), "{:?}", u.app.ui.last_error); +} + +#[test] +fn a_variable_duplicated_in_a_group_stays_in_it_and_in_view() { + let mut u = window_with_groups(); + let group = leftmost(&mut u, "space"); + click(&mut u, group, PointerButton::Primary); + let row = leftmost(&mut u, "sm"); + click(&mut u, row, PointerButton::Secondary); + let duplicate = text_center(&flat(&u.frame_output(vec![]).shapes), "Duplicate"); + click(&mut u, duplicate, PointerButton::Primary); + assert_eq!(names(&u), ["color/brand", "space/sm", "space/sm copy"]); + assert!(shown(&mut u, "sm copy")); +} + +fn create_number(u: &mut Ui) { + let create = text_center(&flat(&u.frame_output(vec![]).shapes), "+ Create variable"); + click(u, create, PointerButton::Primary); + let number = text_center(&flat(&u.frame_output(vec![]).shapes), "Number"); + click(u, number, PointerButton::Primary); +} + +fn type_and_enter(u: &mut Ui, typed: &str) { + u.frame(vec![Event::Text(typed.into())]); + for pressed in [true, false] { + u.frame(vec![Event::Key { key: Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }]); + } + settle(u); +} + +#[test] +fn a_name_of_slashes_alone_leaves_the_variable_in_its_group() { + for typed in ["/", " / / "] { + let mut u = window_with_groups(); + let group = leftmost(&mut u, "space"); + click(&mut u, group, PointerButton::Primary); + create_number(&mut u); + type_and_enter(&mut u, typed); + assert_eq!(names(&u), ["color/brand", "space/Number", "space/sm"], "{typed:?}"); + } +} + +#[test] +fn a_new_collection_takes_its_first_variable_outside_the_group_shown_before() { + let mut u = window_with_groups(); + let group = leftmost(&mut u, "space"); + click(&mut u, group, PointerButton::Primary); + let heading = leftmost(&mut u, "Collections"); + let (_, at, _) = texts(&flat(&u.frame_output(vec![]).shapes)).into_iter().find(|(t, ..)| t == "Collections").unwrap(); + click(&mut u, Pos2::new(at.x - 16.0 + 200.0 - 20.0, heading.y), PointerButton::Primary); + assert_eq!(u.app.session.doc().unwrap().variables.collections.len(), 2, "the + by Collections made one"); + type_and_enter(&mut u, "Sizes"); + create_number(&mut u); + assert_eq!(names(&u), ["Number", "color/brand", "space/sm"]); +} diff --git a/docs/components-parity.md b/docs/components-parity.md index fa4d2494e..48a9486c1 100644 --- a/docs/components-parity.md +++ b/docs/components-parity.md @@ -1,6 +1,6 @@ # Components, variants, styles and variables parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (a style of one library that reaches a file through another library's component is, in a file linking both, the first library's own bound copy, so its modes colour it (#2414); with a variant selected, its property dropdowns show its own values and choosing one renames only that variant, instead of setting the set's default and moving the variants (#2349); library analytics count insertions and detachments of styles and variables; combining components gives every variant the properties any of them had; renaming a variable group to a path with `/` nests it under a parent group instead of turning the slash into a hyphen (#2353); a group's context menu in the Local variables window has Duplicate group, a copy named after it plus " 2" holding a copy of every variable, in one undo step (#2084); pages take a variable mode: with nothing selected the Design panel's Page section shows a Variable modes section, Auto or a mode of each collection that has more than one, as the help center says ("Apply variable mode" in the Page section of the right sidebar) (#2215); a text style binds a number variable to its weight (#2174); an instance lists only the properties its variant's layers use and long property names are cut to one line (#2022); with several layers selected the Design panel header's component button offers Create multiple components (#2088); the Local variables window selects several variables (click, Shift+click for a range, Cmd/Ctrl+click to toggle, Escape to clear) and delete, move to a group and scope act on the selected local variables in one undo step (#2002); text styles carry paragraph spacing and indent, the list style and the OpenType features, as the Supported in text styles table of Create and apply text styles says (#1829); a layer's effect binding takes only a field its effect has; Go to main component on an instance of a library component opens the library file in a tab and selects the main there; glass effects take variables; Delete on a layer inside an instance hides it as an override instead of being refused, as the help center says: "Figma will only toggle the layer's visibility instead of removing it"; library analytics list how many layers and files use each style and variable; SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; a typed or stored variable, collection or mode id names only the object with that id (#1613); colour variables can be calculated from other colours per mode — `{alpha}` replaces a colour's alpha, `{mix}` blends two — and follow them (#1280); stored variable and collection references keep their identity when another object is named like their id (follow-up to #1542); a component set's property rows fit the 240 px right panel: variant values wrap two to a line there and every + and − stays in view; opening a file contacts no team library server it names until you check it (#1097); an explicit variables file path (`variable.import`, the `variables` of `file.open` and `file.import`) is refused past 256 MiB or when it isn't a regular file, as the sibling `variables.json` already was (part of #1114); component properties keep the order they were made in when one is renamed, and Make slot asks for the slot's name first (#1536, #1537); components can't contain their own instances, directly or through others (#1084); the instance-swap menus have a search field (#1338); an instance-swap property's default menu scrolls (#1338); variables on a text style's fields from the style editor; instance-swap properties in the component playground; duplicating or Alt-dragging a main component makes an instance of it (#892); a bound colour variable's alpha applies once (#802); variables import reads `variables` outside `meta` and warns when it imports none (#790); variant properties reorder by drag; library files saved right after a read are read again; Hide when publishing note corrected; size and resizing overrides of layers inside instances (#731); variables export in the browser as a download; core editor leftovers: component playground, variables inside styles; layers and assets panels behaviour suite and fixes; extended collections tail; styles and variables behaviour suite and fixes; components behaviour suite and fixes; team libraries on the server, library usage and swapping a library; extended collections, variables import/export, gradient stops and variant properties bound to variables) · **Target:** Figma Design (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (with a variable group shown in the Local variables window, Create variable makes the variable in that group, and renaming a variable in its row changes the part shown and keeps its group; a style of one library that reaches a file through another library's component is, in a file linking both, the first library's own bound copy, so its modes colour it (#2414); with a variant selected, its property dropdowns show its own values and choosing one renames only that variant, instead of setting the set's default and moving the variants (#2349); library analytics count insertions and detachments of styles and variables; combining components gives every variant the properties any of them had; renaming a variable group to a path with `/` nests it under a parent group instead of turning the slash into a hyphen (#2353); a group's context menu in the Local variables window has Duplicate group, a copy named after it plus " 2" holding a copy of every variable, in one undo step (#2084); pages take a variable mode: with nothing selected the Design panel's Page section shows a Variable modes section, Auto or a mode of each collection that has more than one, as the help center says ("Apply variable mode" in the Page section of the right sidebar) (#2215); a text style binds a number variable to its weight (#2174); an instance lists only the properties its variant's layers use and long property names are cut to one line (#2022); with several layers selected the Design panel header's component button offers Create multiple components (#2088); the Local variables window selects several variables (click, Shift+click for a range, Cmd/Ctrl+click to toggle, Escape to clear) and delete, move to a group and scope act on the selected local variables in one undo step (#2002); text styles carry paragraph spacing and indent, the list style and the OpenType features, as the Supported in text styles table of Create and apply text styles says (#1829); a layer's effect binding takes only a field its effect has; Go to main component on an instance of a library component opens the library file in a tab and selects the main there; glass effects take variables; Delete on a layer inside an instance hides it as an override instead of being refused, as the help center says: "Figma will only toggle the layer's visibility instead of removing it"; library analytics list how many layers and files use each style and variable; SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; a typed or stored variable, collection or mode id names only the object with that id (#1613); colour variables can be calculated from other colours per mode — `{alpha}` replaces a colour's alpha, `{mix}` blends two — and follow them (#1280); stored variable and collection references keep their identity when another object is named like their id (follow-up to #1542); a component set's property rows fit the 240 px right panel: variant values wrap two to a line there and every + and − stays in view; opening a file contacts no team library server it names until you check it (#1097); an explicit variables file path (`variable.import`, the `variables` of `file.open` and `file.import`) is refused past 256 MiB or when it isn't a regular file, as the sibling `variables.json` already was (part of #1114); component properties keep the order they were made in when one is renamed, and Make slot asks for the slot's name first (#1536, #1537); components can't contain their own instances, directly or through others (#1084); the instance-swap menus have a search field (#1338); an instance-swap property's default menu scrolls (#1338); variables on a text style's fields from the style editor; instance-swap properties in the component playground; duplicating or Alt-dragging a main component makes an instance of it (#892); a bound colour variable's alpha applies once (#802); variables import reads `variables` outside `meta` and warns when it imports none (#790); variant properties reorder by drag; library files saved right after a read are read again; Hide when publishing note corrected; size and resizing overrides of layers inside instances (#731); variables export in the browser as a download; core editor leftovers: component playground, variables inside styles; layers and assets panels behaviour suite and fixes; extended collections tail; styles and variables behaviour suite and fixes; components behaviour suite and fixes; team libraries on the server, library usage and swapping a library; extended collections, variables import/export, gradient stops and variant properties bound to variables) · **Target:** Figma Design (desktop app 126.10.7) Design systems are why teams adopt Figma. **Components: breadth ~96%, ready ~72%. Styles and variables: breadth ~95%, ready ~76% (estimated).** QA'd with a synthetic design system of ~300 @@ -65,7 +65,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`. | Editing a style updates its layers; detach and delete keep values; editing a styled property unlinks that style | done | an edited fill/stroke/effect/grid list or text chars unlink; applying a style replaces variables bound to what it sets; text styles on text layers only | | Organising styles: folders by `/` names, order, duplicate, rename folder, Local styles list | done | `style.move` (into a folder renames), `style.duplicate` (right below), `style.renameFolder`; the page's Local styles list by type and folder (drag to reorder, right-click) | | Variables inside styles (paint, effect, grid and text styles; each user resolves them in its own modes) | done | `style.bind`, `style_vars_tests`; the editor binds paint colours, shadow colours, blur radii, grid sizes and a text style's font, font style (a face name from a string variable, or a numeric weight from a number variable, which picks the nearest face and a variable font's `wght` axis), size, line height and letter spacing, the rest through the command; a bound line height is applied in pixels, as the reference tool does (measured 2026-11-10) | -| Variables: colour, number, string, boolean; collections, modes, aliases, scopes, groups | done | behaviour suite: `variables_behaviour_tests.rs`; aliases same type, no loops (also on create); colour calculations per mode (`{alpha}`: a colour variable with its alpha replaced, `{mix}`: a per-channel blend of two colour variables or literals; they compose, can't loop, and bound layers, modes and undo follow them; REST, CSS, Penpot and `.fig` exports write the colour they show in each of their collection's modes, other collections in their default modes; read-only in the panel, which can swap one for an alias or detach it; `variables_colour_tests.rs`), beyond the incumbent, whose variables only alias; scopes filter pickers only; several variables can be selected in the editor (Shift and Cmd/Ctrl click) and deleted, moved to a group or rescoped at once; a group can be duplicated from its row's menu (Duplicate group, one undo step); the window resizes from its edges and corners (minimum 600 x 240) and keeps its size and place while the app runs, #2354 | +| Variables: colour, number, string, boolean; collections, modes, aliases, scopes, groups | done | behaviour suite: `variables_behaviour_tests.rs`; aliases same type, no loops (also on create); colour calculations per mode (`{alpha}`: a colour variable with its alpha replaced, `{mix}`: a per-channel blend of two colour variables or literals; they compose, can't loop, and bound layers, modes and undo follow them; REST, CSS, Penpot and `.fig` exports write the colour they show in each of their collection's modes, other collections in their default modes; read-only in the panel, which can swap one for an alias or detach it; `variables_colour_tests.rs`), beyond the incumbent, whose variables only alias; scopes filter pickers only; several variables can be selected in the editor (Shift and Cmd/Ctrl click) and deleted, moved to a group or rescoped at once; a group can be duplicated from its row's menu (Duplicate group, one undo step); Create variable makes the variable in the group shown, and a row's rename edits the name's last part; the window resizes from its edges and corners (minimum 600 x 240) and keeps its size and place while the app runs, #2354 | | Modes: add, duplicate, rename, delete, set as default / reorder | done | layers on Auto follow a new default; explicit modes stay | | Deleting a bound variable or its collection | done | layers keep their last value and are unbound; aliases to it take its values and colour calculations reading it keep the colour they show | | Code syntax per platform (Web, iOS, Android) | done | generated CSS uses the Web name, SwiftUI the iOS one and Compose the Android one (a variable without one keeps its value there); in the variables JSON; ArkUI and Flutter have no platform of their own and write values | @@ -80,6 +80,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`. | Date | Change | Summary | |---|---|---| +| 2026-11-19 | patch | M3: with a group selected in the Local variables window, + Create variable named the new variable without the group, so it went to the collection's top level and the table, showing the group, didn't show it; only All variables did. It's now made in the group shown (`space/Number`), as in Figma, where duplicating already kept the group. Renaming a variable in its row edited its whole name while the row shows the last part, so typing a name over a new grouped variable moved it out of the group; the field now edits the part shown and keeps the group (the Edit variable window still edits the whole name), and ignores a name of slashes alone. Creating a collection clears the group shown. Tests: `variables_group_create_tests` | | 2026-11-19 | patch | M3, #2414: a kit's style used by a component of a second library reached a file linking both as a second, unbound copy (`::S:1`) frozen in the kit's default mode, so a mode set on the kit's collection didn't colour it (from two hops on, every such style). Publishing now keeps the variables the published styles bind and where the file's copies of other libraries' styles, variables and collections came from; importing files such a copy under that library when the file links it, so it is the file's own bound copy. Test: `library_style_hops_tests::a_kit_style_through_another_library_is_the_kits_bound_copy`; the issue's four-file chain renders Brand and Alt everywhere. Grade unchanged. | | 2026-11-19 | patch | M3, #2349: with one variant of a set selected, the Design panel's variant property dropdowns showed the set's default values, and choosing a value set the default, so the variants swapped places. They now show the selected variant's own values (hover: "This variant's value"), and choosing one renames that variant only; with the set selected they still set its default. Test: `variant_own_value_tests::a_selected_variants_dropdown_shows_and_sets_its_own_value`. Grade unchanged. | | 2026-11-18 | minor | M3, gap 10: library analytics count insertions and detachments of styles and variables. Applying one, or copying or duplicating content that uses it, inserts it; the Detach button detaches it; an instance counts as its component alone. Show usage and `library.usage` give them per style and variable over the chosen period. Modes aren't counted. Numbers unchanged. Tests: `library_asset_counts_tests`, `library_assets_tests`. |