mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-29 09:46:34 +01:00
Merge upstream/main into feat/mind-maps-ui-2226
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
fea921fcc4
34 files changed
+621
-89
No files matched your search
@@ -14,6 +14,40 @@ use crate::{Result, bad};
|
||||
/// Deepest params nesting the resolver walks before giving up.
|
||||
const MAX_DEPTH: usize = 64;
|
||||
|
||||
/// How much referenced data (values and string bytes) the params of one step may copy in.
|
||||
const MAX_EXPANDED: usize = 8 << 20;
|
||||
|
||||
/// What copying `v` costs: its values and string bytes, counting stops past `limit`.
|
||||
fn weight(v: &Value, limit: usize) -> usize {
|
||||
let mut total = 0usize;
|
||||
let mut stack = vec![v];
|
||||
while let Some(v) = stack.pop() {
|
||||
total += 1;
|
||||
match v {
|
||||
Value::String(s) => total += s.len(),
|
||||
// Checked before they are queued, so a huge list can't grow the worklist past the limit.
|
||||
Value::Array(a) => {
|
||||
if total + a.len() > limit {
|
||||
return total + a.len();
|
||||
}
|
||||
stack.extend(a);
|
||||
}
|
||||
Value::Object(o) => {
|
||||
total += o.keys().map(String::len).sum::<usize>();
|
||||
if total + o.len() > limit {
|
||||
return total + o.len();
|
||||
}
|
||||
stack.extend(o.values());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if total > limit {
|
||||
return total;
|
||||
}
|
||||
}
|
||||
total
|
||||
}
|
||||
|
||||
/// One step of a batch: a command, its params and the name later steps can call it by.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct BatchStep {
|
||||
@@ -99,30 +133,32 @@ impl BatchScope {
|
||||
|
||||
/// `params` of the next step with every reference in it replaced.
|
||||
pub(crate) fn resolve(&self, params: &Value) -> Result<Value> {
|
||||
self.resolve_in(params, 0)
|
||||
let mut left = MAX_EXPANDED;
|
||||
self.resolve_in(params, 0, &mut left)
|
||||
}
|
||||
|
||||
fn resolve_in(&self, v: &Value, depth: usize) -> Result<Value> {
|
||||
/// `left`: how much referenced data one step's params may still copy in.
|
||||
fn resolve_in(&self, v: &Value, depth: usize, left: &mut usize) -> Result<Value> {
|
||||
let step = self.next_step();
|
||||
if depth > MAX_DEPTH {
|
||||
return Err(bad("command.batch", format!("step {step}: params nest deeper than {MAX_DEPTH} levels")));
|
||||
}
|
||||
match v {
|
||||
Value::Object(o) if o.contains_key("$step") || o.contains_key("$ref") => self.reference(o),
|
||||
Value::Object(o) if o.contains_key("$step") || o.contains_key("$ref") => self.reference(o, left),
|
||||
Value::Object(o) => {
|
||||
let mut out = Map::with_capacity(o.len());
|
||||
for (k, x) in o {
|
||||
out.insert(k.clone(), self.resolve_in(x, depth + 1)?);
|
||||
out.insert(k.clone(), self.resolve_in(x, depth + 1, left)?);
|
||||
}
|
||||
Ok(Value::Object(out))
|
||||
}
|
||||
Value::Array(a) => a.iter().map(|x| self.resolve_in(x, depth + 1)).collect::<Result<Vec<_>>>().map(Value::Array),
|
||||
Value::Array(a) => a.iter().map(|x| self.resolve_in(x, depth + 1, left)).collect::<Result<Vec<_>>>().map(Value::Array),
|
||||
_ => Ok(v.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The value a `{"$step": n}` or `{"$ref": "name"}` object (with an optional `field`) stands for.
|
||||
fn reference(&self, o: &Map<String, Value>) -> Result<Value> {
|
||||
fn reference(&self, o: &Map<String, Value>, left: &mut usize) -> Result<Value> {
|
||||
let step = self.next_step();
|
||||
let fail = |msg: String| bad("command.batch", format!("step {step}: {msg}"));
|
||||
let key = if o.contains_key("$step") { "$step" } else { "$ref" };
|
||||
@@ -153,7 +189,10 @@ impl BatchScope {
|
||||
Some(_) => return Err(fail("`field` must be a string".into())),
|
||||
};
|
||||
let result = self.results.get(n).ok_or_else(|| fail(format!("{who} has no result")))?;
|
||||
lookup(result, path).cloned().map_err(|why| fail(format!("{who}'s result has no `{path}`{why}")))
|
||||
let value = lookup(result, path).map_err(|why| fail(format!("{who}'s result has no `{path}`{why}")))?;
|
||||
// Counted before copying: a few references to one big result can't multiply it.
|
||||
*left = left.checked_sub(weight(value, *left)).ok_or_else(|| fail("the references copy more than the batch may expand".into()))?;
|
||||
Ok(value.clone())
|
||||
}
|
||||
|
||||
/// Most step names a missing-reference error lists.
|
||||
@@ -218,3 +257,27 @@ fn kind(v: &Value) -> &'static str {
|
||||
Value::Object(_) => "an object",
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod expansion_tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn references_copy_a_bounded_amount_into_one_step() {
|
||||
let steps = [BatchStep::new("a", json!({})), BatchStep::new("b", json!({}))];
|
||||
let mut scope = BatchScope::new(&steps).unwrap();
|
||||
// A result of about 1 MB.
|
||||
scope.push(json!({"ids": vec!["x".repeat(1000); 1000]}));
|
||||
let refs = |n: usize| json!({"all": vec![json!({"$step": 0, "field": "ids"}); n]});
|
||||
assert!(scope.resolve(&refs(4)).is_ok());
|
||||
let err = scope.resolve(&refs(200)).unwrap_err().to_string();
|
||||
assert!(err.contains("more than the batch may expand"), "{err}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_huge_list_is_refused_before_it_is_queued() {
|
||||
assert!(weight(&json!(vec![0; 100_000]), 1000) > 1000);
|
||||
assert!(weight(&json!(vec![0; 10]), 1000) <= 1000);
|
||||
}
|
||||
}
|
||||
@@ -165,6 +165,14 @@ pub fn node_json(doc: &Document, id: NodeId, depth: usize) -> Value {
|
||||
|
||||
/// A node's selected properties, applied at every level of its subtree.
|
||||
pub fn node_json_with_options(doc: &Document, id: NodeId, depth: usize, options: &InspectOptions) -> Value {
|
||||
node_json_in(doc, id, depth, options, &GridCells::default())
|
||||
}
|
||||
|
||||
/// The cells of the grid frames met so far in one inspection, so a grid's geometry is worked out
|
||||
/// once, not once per child.
|
||||
type GridCells = std::cell::RefCell<std::collections::HashMap<NodeId, std::collections::HashMap<NodeId, figcraft_layout::GridCell>>>;
|
||||
|
||||
fn node_json_in(doc: &Document, id: NodeId, depth: usize, options: &InspectOptions, grids: &GridCells) -> Value {
|
||||
let Some(n) = doc.node(id) else { return Value::Null };
|
||||
let mut v = json!({"id": n.id});
|
||||
let Some(o) = v.as_object_mut() else { return v };
|
||||
@@ -176,7 +184,7 @@ pub fn node_json_with_options(doc: &Document, id: NodeId, depth: usize, options:
|
||||
if !n.is_page() {
|
||||
base_props(doc, n, id, o, options);
|
||||
paint_props(n, o, options);
|
||||
layout_props(doc, n, o, options);
|
||||
layout_props(doc, n, o, options, grids);
|
||||
dev_props(doc, n, o, options);
|
||||
}
|
||||
// Layer data written with `node.set {props: {pluginData}}` (pages too).
|
||||
@@ -189,7 +197,7 @@ pub fn node_json_with_options(doc: &Document, id: NodeId, depth: usize, options:
|
||||
}
|
||||
if !n.children.is_empty() {
|
||||
if depth > 0 {
|
||||
o.insert("children".into(), Value::Array(n.children.iter().map(|c| node_json_with_options(doc, *c, depth - 1, options)).collect()));
|
||||
o.insert("children".into(), Value::Array(n.children.iter().map(|c| node_json_in(doc, *c, depth - 1, options, grids)).collect()));
|
||||
} else {
|
||||
o.insert("childCount".into(), json!(n.children.len()));
|
||||
}
|
||||
@@ -286,7 +294,7 @@ fn paint_props(n: &Node, o: &mut serde_json::Map<String, Value>, options: &Inspe
|
||||
}
|
||||
}
|
||||
|
||||
fn layout_props(doc: &Document, n: &Node, o: &mut serde_json::Map<String, Value>, options: &InspectOptions) {
|
||||
fn layout_props(doc: &Document, n: &Node, o: &mut serde_json::Map<String, Value>, options: &InspectOptions, grids: &GridCells) {
|
||||
if let Some(l) = &n.layout {
|
||||
insert_prop(o, options, "layout", || camel(serde_json::to_value(l).unwrap_or(Value::Null)));
|
||||
}
|
||||
@@ -303,11 +311,14 @@ fn layout_props(doc: &Document, n: &Node, o: &mut serde_json::Map<String, Value>
|
||||
insert_prop(o, options, k, || json!(v));
|
||||
}
|
||||
}
|
||||
if let Some(cell) = (parent_al && options.includes("gridCell"))
|
||||
.then(|| n.parent.and_then(|p| figcraft_layout::grid_geometry(doc, p)))
|
||||
.flatten()
|
||||
.and_then(|g| g.cells.into_iter().find(|c| c.id == n.id))
|
||||
{
|
||||
let cell = (parent_al && options.includes("gridCell")).then_some(n.parent).flatten().and_then(|p| {
|
||||
let mut grids = grids.borrow_mut();
|
||||
let cells = grids
|
||||
.entry(p)
|
||||
.or_insert_with(|| figcraft_layout::grid_geometry(doc, p).map(|g| g.cells.into_iter().map(|c| (c.id, c)).collect()).unwrap_or_default());
|
||||
cells.get(&n.id).copied()
|
||||
});
|
||||
if let Some(cell) = cell {
|
||||
insert_prop(o, options, "gridCell", || {
|
||||
json!({"column": cell.column, "row": cell.row, "columnSpan": cell.column_span, "rowSpan": cell.row_span,
|
||||
"anchored": cl.grid_column.is_some() || cl.grid_row.is_some(), "alignH": cl.grid_align_h, "alignV": cl.grid_align_v})
|
||||
|
||||
@@ -182,6 +182,9 @@ fn table_edits_add_and_remove_rows_and_columns_keeping_text() {
|
||||
|
||||
#[test]
|
||||
fn a_double_click_types_in_the_cell_and_its_row_grows_with_the_text() {
|
||||
// Measure with system fonts when the optional craft-fonts checkout is absent,
|
||||
// without depending on another test having scanned them first.
|
||||
figcraft_text::scan_system_fonts();
|
||||
let mut s = board();
|
||||
let r = s.execute("board.table", &json!({"x": 0, "y": 0})).unwrap();
|
||||
let t = id(&r, "id");
|
||||
|
||||
@@ -179,7 +179,8 @@ pub(super) fn nudge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// no undo step.
|
||||
let mut work = s.doc()?.clone();
|
||||
let doc = &mut work;
|
||||
let ids = roots(doc, &ids);
|
||||
// A locked layer (or one in a locked layer) ignores the arrow keys.
|
||||
let ids: Vec<NodeId> = roots(doc, &ids).into_iter().filter(|i| !crate::tools::locked_in(doc, *i)).collect();
|
||||
let mut changed = false;
|
||||
// Children in an auto layout flow move one place instead (see `al_keys`).
|
||||
for i in &ids {
|
||||
@@ -214,6 +215,9 @@ pub(super) fn nudge_size(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let ids = req_targets("transform.nudgeSize", s, p)?;
|
||||
let ids = roots(s.doc()?, &ids);
|
||||
for i in ids {
|
||||
if crate::tools::locked_in(s.doc()?, i) {
|
||||
continue;
|
||||
}
|
||||
let Some((w, h)) = s.doc()?.node(i).map(|n| (n.width, n.height)) else { continue };
|
||||
let mut q = serde_json::Map::new();
|
||||
q.insert("ids".into(), json!([i]));
|
||||
@@ -236,9 +240,16 @@ pub(super) fn toggle(s: &mut Session, p: &Value, what: &str) -> Result<Value> {
|
||||
// Figma: if any is visible, hide all (and vice versa).
|
||||
let value = explicit.unwrap_or_else(|| match what {
|
||||
"visible" => !ids.iter().all(|i| doc.node(*i).is_some_and(|n| n.visible)),
|
||||
_ => !ids.iter().all(|i| doc.node(*i).is_some_and(|n| n.locked)),
|
||||
// A child of a locked layer counts as locked: its own flag can't be toggled while the
|
||||
// parent is locked.
|
||||
_ => !ids.iter().all(|i| crate::tools::locked_in(doc, *i)),
|
||||
});
|
||||
for i in &ids {
|
||||
// Lock/Unlock leaves a child of a locked layer alone, as its padlock does: its own flag must
|
||||
// still hold once the parent is unlocked. An explicit `locked` (scripts) sets it anyway.
|
||||
let under_lock = |i: NodeId| doc.ancestors(i).into_iter().any(|a| doc.node(a).is_some_and(|n| n.locked));
|
||||
let skip: Vec<NodeId> =
|
||||
if what == "locked" && explicit.is_none() { ids.iter().copied().filter(|i| under_lock(*i)).collect() } else { Vec::new() };
|
||||
for i in ids.iter().filter(|i| !skip.contains(i)) {
|
||||
let n = doc.get_mut(*i)?;
|
||||
if what == "visible" {
|
||||
n.visible = value;
|
||||
|
||||
@@ -270,6 +270,13 @@ mod tests {
|
||||
assert_eq!(info["gridCell"]["column"], json!(2));
|
||||
assert_eq!(info["gridCell"]["row"], json!(1));
|
||||
assert_eq!(info["gridCell"]["anchored"], json!(true));
|
||||
// Inspected together with the frame, each child still gets its own cell.
|
||||
let all = crate::inspect::node_json(s.doc().unwrap(), f, 1);
|
||||
let cells: Vec<(Value, Value)> =
|
||||
all["children"].as_array().unwrap().iter().map(|c| (c["gridCell"]["column"].clone(), c["gridCell"]["row"].clone())).collect();
|
||||
assert_eq!(cells[3], (json!(2), json!(1)));
|
||||
assert_eq!(cells[0].0, json!(0));
|
||||
assert!(cells.iter().all(|(c, r)| c.is_number() && r.is_number()), "{cells:?}");
|
||||
ex(&mut s, "node.set", json!({"id": kids[3], "props": {"gridColumn": "auto", "gridRow": null}}));
|
||||
assert_eq!(node(&s, kids[3]).child_layout.grid_column, None);
|
||||
// Fewer columns drop the extra tracks.
|
||||
|
||||
@@ -285,3 +285,16 @@ fn vue_layer_trees_import_connected_components_in_script_setup() {
|
||||
assert!(code.starts_with(want), "{code}");
|
||||
assert_eq!(code.matches("import Card").count(), 1, "{code}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_entries_for_one_component_each_link() {
|
||||
let mut s = Session::new();
|
||||
let (_, hover) = button(&mut s);
|
||||
let links: Vec<Value> = (0..crate::code_connect::MAX_FILE_LINKS)
|
||||
.map(|i| json!({"component": "Button", "language": if i % 2 == 0 { "react" } else { "vue" }, "name": "Button", "template": "<Button />"}))
|
||||
.collect();
|
||||
let r = ex(&mut s, "codeConnect.import", json!({"json": {"version": 1, "links": links}}));
|
||||
assert_eq!(r["linked"], crate::code_connect::MAX_FILE_LINKS, "{r}");
|
||||
let i = idv(&ex(&mut s, "instance.create", json!({"component": hover, "x": 0, "y": 500})));
|
||||
assert_eq!(code(&mut s, i, "react"), "<Button />\n");
|
||||
}
|
||||
@@ -669,7 +669,12 @@ fn import(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
let doc = s.doc()?;
|
||||
// Components and sets by name (variants are linked through their set).
|
||||
let owners: Vec<(String, NodeId)> = doc.nodes().filter(|n| owner(doc, n.id) == Some(n.id)).map(|n| (n.name.clone(), n.id)).collect();
|
||||
let mut owners: std::collections::HashMap<&str, Vec<NodeId>> = std::collections::HashMap::new();
|
||||
for n in doc.nodes().filter(|n| owner(doc, n.id) == Some(n.id)) {
|
||||
owners.entry(n.name.as_str()).or_default().push(n.id);
|
||||
}
|
||||
// What each component looks like, worked out once however many entries name it.
|
||||
let mut described: std::collections::HashMap<NodeId, Option<Component>> = std::collections::HashMap::new();
|
||||
let mut warnings: Vec<String> = Vec::new();
|
||||
let mut apply: Vec<(NodeId, CodeLink)> = Vec::new();
|
||||
for (i, e) in entries.iter().enumerate() {
|
||||
@@ -689,13 +694,13 @@ fn import(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
name: name.into(),
|
||||
template: template.into(),
|
||||
};
|
||||
let matches: Vec<NodeId> = owners.iter().filter(|(n, _)| n == component).map(|(_, id)| *id).collect();
|
||||
let matches = owners.get(component).cloned().unwrap_or_default();
|
||||
if matches.is_empty() {
|
||||
warnings.push(format!("link {}: no component named {component:?}", i + 1));
|
||||
}
|
||||
for id in matches {
|
||||
let Some(c) = main_of(doc, id).and_then(|m| describe(doc, m)) else { continue };
|
||||
match check(&c, &link, lang) {
|
||||
let Some(c) = described.entry(id).or_insert_with(|| main_of(doc, id).and_then(|m| describe(doc, m))).as_ref() else { continue };
|
||||
match check(c, &link, lang) {
|
||||
Ok(_) => apply.push((id, link.clone())),
|
||||
Err(err) => warnings.push(format!("link {} ({component}): {err}", i + 1)),
|
||||
}
|
||||
|
||||
@@ -421,6 +421,8 @@ mod live_signal_tests;
|
||||
#[cfg(test)]
|
||||
mod live_tests;
|
||||
#[cfg(test)]
|
||||
mod lock_behaviour_tests;
|
||||
#[cfg(test)]
|
||||
mod mask_tests;
|
||||
#[cfg(test)]
|
||||
mod masks_behaviour_tests;
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
//! Locked layers, as measured in Figma's web app (2026-11-10) and described in the help-center
|
||||
//! article "Lock and unlock layers": the canvas never selects a locked layer or a child of a locked
|
||||
//! frame; a locked layer selected in the layers panel has no handles and ignores the arrow keys, but
|
||||
//! its properties still edit; a child of a locked frame can't be locked or unlocked on its own.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::Session;
|
||||
use crate::params::id_of;
|
||||
use crate::tools::{PointerEvent, PointerKind, handle_at};
|
||||
use figcraft_doc::NodeId;
|
||||
use figcraft_geom::Point;
|
||||
|
||||
fn ex(s: &mut Session, cmd: &str, p: Value) -> Value {
|
||||
s.execute(cmd, &p).unwrap_or_else(|e| panic!("{cmd}: {e}"))
|
||||
}
|
||||
|
||||
fn rect(s: &mut Session, x: f64, y: f64, parent: Option<NodeId>) -> NodeId {
|
||||
let mut p = json!({"x": x, "y": y, "width": 40, "height": 40});
|
||||
if let Some(parent) = parent {
|
||||
p["parent"] = json!(parent);
|
||||
}
|
||||
id_of(&ex(s, "shape.rectangle", p)["id"]).unwrap()
|
||||
}
|
||||
|
||||
/// A frame `f` (0,0 300x200) holding rectangle `d` (20,20 40x40); a locked rectangle `lk`
|
||||
/// (400,0 40x40) and an unlocked one `r` (400,100 40x40) on the page.
|
||||
fn scene(s: &mut Session) -> (NodeId, NodeId, NodeId, NodeId) {
|
||||
let f = id_of(&ex(s, "frame.create", json!({"x": 0, "y": 0, "width": 300, "height": 200}))["id"]).unwrap();
|
||||
let d = rect(s, 20.0, 20.0, Some(f));
|
||||
let lk = rect(s, 400.0, 0.0, None);
|
||||
let r = rect(s, 400.0, 100.0, None);
|
||||
ex(s, "object.toggleLock", json!({"ids": [lk], "locked": true}));
|
||||
(f, d, lk, r)
|
||||
}
|
||||
|
||||
fn ev(kind: PointerKind, x: f64, y: f64, cmd: bool) -> PointerEvent {
|
||||
let mut e = PointerEvent::at(kind, x, y, 1.0);
|
||||
e.cmd = cmd;
|
||||
e
|
||||
}
|
||||
|
||||
fn click(s: &mut Session, x: f64, y: f64, cmd: bool) {
|
||||
s.pointer(&ev(PointerKind::Down, x, y, cmd)).unwrap();
|
||||
s.pointer(&ev(PointerKind::Up, x, y, cmd)).unwrap();
|
||||
}
|
||||
|
||||
fn origin(s: &Session, id: NodeId) -> (f64, f64) {
|
||||
let b = s.doc().unwrap().world_bounds(id).unwrap();
|
||||
(b.x0, b.y0)
|
||||
}
|
||||
|
||||
fn size(s: &Session, id: NodeId) -> (f64, f64) {
|
||||
let b = s.doc().unwrap().world_bounds(id).unwrap();
|
||||
(b.width(), b.height())
|
||||
}
|
||||
|
||||
fn locked(s: &Session, id: NodeId) -> bool {
|
||||
s.doc().unwrap().node(id).unwrap().locked
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canvas_never_selects_a_locked_layer_or_a_locked_frames_child() {
|
||||
let mut s = Session::new();
|
||||
let (f, d, _lk, _r) = scene(&mut s);
|
||||
click(&mut s, 420.0, 20.0, false);
|
||||
assert!(s.selection().is_empty(), "a click on a locked layer selects nothing");
|
||||
click(&mut s, 420.0, 20.0, true);
|
||||
assert!(s.selection().is_empty(), "Cmd/Ctrl-click on a locked layer selects nothing");
|
||||
s.pointer(&ev(PointerKind::Down, 390.0, -10.0, false)).unwrap();
|
||||
s.pointer(&ev(PointerKind::Move, 450.0, 50.0, false)).unwrap();
|
||||
s.pointer(&ev(PointerKind::Up, 450.0, 50.0, false)).unwrap();
|
||||
assert!(s.selection().is_empty(), "a marquee over a locked layer selects nothing");
|
||||
ex(&mut s, "object.toggleLock", json!({"ids": [f], "locked": true}));
|
||||
click(&mut s, 30.0, 30.0, false);
|
||||
assert!(!s.selection().contains(&d), "a click on a child of a locked frame doesn't select it");
|
||||
click(&mut s, 30.0, 30.0, true);
|
||||
assert!(s.selection().is_empty(), "Cmd/Ctrl-click on a child of a locked frame selects nothing");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_panel_selected_locked_layer_has_no_handles_ignores_arrows_and_takes_property_edits() {
|
||||
let mut s = Session::new();
|
||||
let (_f, _d, lk, _r) = scene(&mut s);
|
||||
ex(&mut s, "select.set", json!({"ids": [lk]}));
|
||||
assert_eq!(handle_at(s.doc().unwrap(), &[lk], Point::new(400.0, 0.0), 1.0), None, "no handles on a locked layer");
|
||||
let steps = s.undo_depth();
|
||||
for _ in 0..3 {
|
||||
ex(&mut s, "transform.nudge", json!({"dx": 1}));
|
||||
}
|
||||
assert_eq!(origin(&s, lk), (400.0, 0.0), "the arrow keys don't move a locked layer");
|
||||
ex(&mut s, "transform.nudgeSize", json!({"dw": 1}));
|
||||
assert_eq!(size(&s, lk), (40.0, 40.0), "the resize arrows don't resize a locked layer");
|
||||
assert_eq!(s.undo_depth(), steps, "an arrow that changes nothing adds no undo step");
|
||||
ex(&mut s, "node.set", json!({"id": lk, "props": {"x": 300}}));
|
||||
assert_eq!(origin(&s, lk).0, 300.0, "the X field still moves a locked layer");
|
||||
let before = format!("{:?}", s.doc().unwrap().node(lk).unwrap().fills);
|
||||
ex(&mut s, "fill.set", json!({"ids": [lk], "color": "#ff0000"}));
|
||||
assert_ne!(format!("{:?}", s.doc().unwrap().node(lk).unwrap().fills), before, "a fill still edits");
|
||||
assert_eq!(s.selection(), vec![lk], "the selection stays the locked layer");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_child_of_a_locked_frame_cannot_be_locked_or_unlocked_on_its_own() {
|
||||
let mut s = Session::new();
|
||||
let (f, d, _lk, _r) = scene(&mut s);
|
||||
ex(&mut s, "object.toggleLock", json!({"ids": [f], "locked": true}));
|
||||
ex(&mut s, "object.toggleLock", json!({"ids": [d]}));
|
||||
assert!(!locked(&s, d), "toggling a child of a locked frame doesn't lock the child");
|
||||
ex(&mut s, "select.set", json!({"ids": [d]}));
|
||||
ex(&mut s, "object.toggleLock", json!({}));
|
||||
assert!(!locked(&s, d), "Lock/Unlock on a panel-selected child of a locked frame does nothing");
|
||||
ex(&mut s, "object.toggleLock", json!({"ids": [f], "locked": false}));
|
||||
click(&mut s, 30.0, 30.0, false);
|
||||
assert_eq!(s.selection(), vec![d], "after unlocking the frame a click selects the child");
|
||||
assert!(!locked(&s, d));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_unlock_on_a_mixed_selection_leaves_a_locked_frames_child_alone() {
|
||||
let mut s = Session::new();
|
||||
let (f, d, _lk, r) = scene(&mut s);
|
||||
ex(&mut s, "object.toggleLock", json!({"ids": [f], "locked": true}));
|
||||
ex(&mut s, "select.set", json!({"ids": [d, r]}));
|
||||
ex(&mut s, "object.toggleLock", json!({}));
|
||||
assert!(locked(&s, r), "the unlocked layer in the selection is locked");
|
||||
assert!(!locked(&s, d), "the locked frame's child keeps its own flag");
|
||||
ex(&mut s, "object.toggleLock", json!({"ids": [f], "locked": false}));
|
||||
click(&mut s, 30.0, 30.0, false);
|
||||
assert_eq!(s.selection(), vec![d], "so unlocking the frame frees the child");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ctrl_shift_l_on_a_panel_selected_locked_layer_unlocks_it() {
|
||||
let mut s = Session::new();
|
||||
let (_f, _d, lk, _r) = scene(&mut s);
|
||||
ex(&mut s, "select.set", json!({"ids": [lk]}));
|
||||
ex(&mut s, "object.toggleLock", json!({}));
|
||||
assert!(!locked(&s, lk), "Lock/Unlock unlocks a locked layer");
|
||||
assert!(handle_at(s.doc().unwrap(), &[lk], Point::new(400.0, 0.0), 1.0).is_some(), "handles return");
|
||||
}
|
||||
Reference in new issue
Block a user