mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-16 07:12:46 +00:00
M1: disable frame selection inside locked instance structure
This commit is contained in:
1 parent
c7fb4e33df
commit
87454911fe
2 files changed
+40
-1
No files matched your search
@@ -96,3 +96,38 @@ fn new_from_selection_is_disabled_for_a_section() {
|
||||
assert_eq!(u.app.session.doc().unwrap().node(frame).unwrap().parent, Some(section));
|
||||
assert_eq!(u.app.session.tool.tool, ToolId::Move);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_from_selection_respects_instance_structure_and_slots() {
|
||||
for slot in [false, true] {
|
||||
let mut s = Session::new();
|
||||
let frame = NodeId(s.execute("frame.create", &json!({"width": 200, "height": 200})).unwrap()["id"].as_u64().unwrap());
|
||||
let content = NodeId(s.execute("frame.create", &json!({"parent": frame, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap());
|
||||
let rect = NodeId(s.execute("shape.rectangle", &json!({"parent": content, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap());
|
||||
let component = NodeId(s.execute("component.create", &json!({"ids": [frame]})).unwrap()["id"].as_u64().unwrap());
|
||||
if slot {
|
||||
s.execute("component.makeSlot", &json!({"id": content})).unwrap();
|
||||
}
|
||||
let instance = NodeId(s.execute("instance.create", &json!({"component": component, "x": 300, "y": 0})).unwrap()["id"].as_u64().unwrap());
|
||||
let doc = s.doc().unwrap();
|
||||
let child = doc.subtree(instance).into_iter().find(|id| doc.node(*id).and_then(|n| n.source) == Some(rect)).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [child]})).unwrap();
|
||||
s.execute("tool.set", &json!({"tool": "frame"})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
let history = u.app.session.undo_depth().0;
|
||||
let parent = u.app.session.doc().unwrap().node(child).unwrap().parent;
|
||||
let (at, disabled) = named_button(&mut u, "New from selection");
|
||||
assert_eq!(disabled, !slot, "only content within a slot can be reframed");
|
||||
click(&mut u, at);
|
||||
assert!(u.app.ui.toast.is_none(), "disabled action must not raise an error");
|
||||
if slot {
|
||||
assert_eq!(u.app.session.undo_depth().0, history + 1);
|
||||
assert_ne!(u.app.session.doc().unwrap().node(child).unwrap().parent, parent);
|
||||
assert_eq!(u.app.session.tool.tool, ToolId::Move);
|
||||
} else {
|
||||
assert_eq!(u.app.session.undo_depth().0, history);
|
||||
assert_eq!(u.app.session.doc().unwrap().node(child).unwrap().parent, parent);
|
||||
assert_eq!(u.app.session.tool.tool, ToolId::Frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,11 @@ use crate::widgets::{self, PAD};
|
||||
/// Whether `object.frameSelection` would frame `selection`: layers on a page, none of them a
|
||||
/// section (sections never go in frames, #1683).
|
||||
fn can_frame(doc: &Document, selection: &[NodeId]) -> bool {
|
||||
!selection.is_empty() && selection.iter().all(|i| doc.node(*i).is_some_and(|n| n.parent.is_some() && !matches!(n.kind, NodeKind::Section { .. })))
|
||||
!selection.is_empty()
|
||||
&& selection.iter().all(|i| doc.node(*i).is_some_and(|n| n.parent.is_some() && !matches!(n.kind, NodeKind::Section { .. })))
|
||||
&& figcraft_engine::cmd::edit::roots(doc, selection)
|
||||
.iter()
|
||||
.all(|id| doc.node(*id).and_then(|n| n.parent).is_some_and(|parent| !figcraft_engine::components::structure_locked(doc, parent)))
|
||||
}
|
||||
|
||||
/// Draw New from selection and the expandable frame-preset categories. New from selection wraps
|
||||
|
||||
Reference in new issue
Block a user