mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Selection Tools: Edit Points Only skips hidden and locked art and keeps the Appearance row
Edit Points Only now leaves out selected paths and groups that are hidden or locked, themselves or through an ancestor. Group expansion looks up explicit anchor picks in a set instead of scanning the selection for each path. Canceling the preview restores the active Appearance row, and a preview or OK that succeeds clears the earlier status error.
This commit is contained in:
1 parent
c1bfae38c2
commit
8d5fb2ff6b
6 files changed
+116
-3
No files matched your search
@@ -254,9 +254,13 @@ fn edit_points_only(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
// Each path once, in selection order, with its points kept: `None` for all of them.
|
||||
let mut seen = HashSet::new();
|
||||
let explicit: HashSet<NodeId> = sel.objects.iter().copied().filter(|id| sel.anchors.contains_key(id)).collect();
|
||||
let mut kept: Vec<(NodeId, usize, Option<BTreeSet<AnchorRef>>)> = vec![];
|
||||
for id in &sel.objects {
|
||||
let Some(n) = doc.node(*id) else { continue };
|
||||
if !doc.ancestry(*id).is_some_and(|ancestors| ancestors.iter().all(|id| doc.node(*id).is_some_and(|n| n.visible && !n.locked))) {
|
||||
continue;
|
||||
}
|
||||
match &n.kind {
|
||||
NodeKind::Path { path, .. } => {
|
||||
let Some(refs) = sel.anchors.get(id) else {
|
||||
@@ -281,7 +285,7 @@ fn edit_points_only(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut inside = vec![];
|
||||
paths_inside(n, guides_locked, &mut inside);
|
||||
for c in inside {
|
||||
if sel.objects.contains(&c.id) && sel.anchors.contains_key(&c.id) {
|
||||
if explicit.contains(&c.id) {
|
||||
continue;
|
||||
}
|
||||
if seen.insert(c.id) {
|
||||
|
||||
@@ -452,6 +452,79 @@ mod edit_points_only {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_or_locked_selected_nodes_and_their_ancestors_are_left_out() {
|
||||
for locked in [false, true] {
|
||||
for target in ["path", "group", "ancestor", "layer"] {
|
||||
let (mut s, a, b) = two();
|
||||
let good = rect(&mut s, 200.0, 10.0, 20.0, 20.0);
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
let group = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
let blocked = match target {
|
||||
"path" => a,
|
||||
"layer" => s.doc().unwrap().doc.layers[0].id,
|
||||
_ => group,
|
||||
};
|
||||
let doc = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc);
|
||||
let node = doc.node_mut(blocked).unwrap();
|
||||
if locked {
|
||||
node.locked = true;
|
||||
} else {
|
||||
node.visible = false;
|
||||
}
|
||||
let selected = if matches!(target, "path" | "ancestor") { a } else { group };
|
||||
s.execute("select.set", &json!({"ids": [good.0, selected.0]})).unwrap();
|
||||
if target == "layer" {
|
||||
let before = s.doc().unwrap().selection.clone();
|
||||
assert!(s.execute(C, &json!({})).is_err());
|
||||
assert_eq!(s.doc().unwrap().selection, before);
|
||||
} else {
|
||||
s.execute(C, &json!({})).unwrap();
|
||||
assert_eq!(picked(&s), (vec![good], BTreeMap::new()), "{target}, locked: {locked}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_expansion_does_not_scan_the_selection_for_each_descendant() {
|
||||
let source = include_str!("../select.rs");
|
||||
let command = source.split("fn edit_points_only(").nth(1).unwrap();
|
||||
assert!(!command.contains("sel.objects.contains(&c.id)"), "descendant lookup must not scan every selected object");
|
||||
|
||||
let (mut s, _, _) = two();
|
||||
let mut groups = vec![];
|
||||
let mut paths = vec![];
|
||||
for x in [10.0, 100.0, 200.0] {
|
||||
let a = rect(&mut s, x, 100.0, 20.0, 20.0);
|
||||
let b = rect(&mut s, x, 150.0, 20.0, 20.0);
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
groups.push(NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap()));
|
||||
paths.extend([a, b]);
|
||||
}
|
||||
s.select(|_, sel| sel.set(groups)).unwrap();
|
||||
s.execute(C, &json!({})).unwrap();
|
||||
assert_eq!(picked(&s), (paths, BTreeMap::new()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canceling_a_selection_preview_restores_the_active_appearance_item() {
|
||||
let (mut s, a, b) = two();
|
||||
mixed(&mut s, a, b);
|
||||
s.execute("appearance.addFill", &json!({})).unwrap();
|
||||
s.execute("appearance.setActiveItem", &json!({"index": 0})).unwrap();
|
||||
let before = s.doc().unwrap().doc.node(a).unwrap().appearance.items.clone();
|
||||
s.begin_interaction("Edit Points Only").unwrap();
|
||||
s.preview(C, &json!({})).unwrap();
|
||||
assert_eq!(s.appearance_item(), None);
|
||||
s.cancel_interaction().unwrap();
|
||||
assert_eq!(s.appearance_item(), Some(0));
|
||||
s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
|
||||
let after = &s.doc().unwrap().doc.node(a).unwrap().appearance.items;
|
||||
assert_ne!(after[0], before[0]);
|
||||
assert_eq!(&after[1..], &before[1..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whole_paths_keep_object_transforms_and_stroke_scaling() {
|
||||
let (mut s, a, _) = two();
|
||||
|
||||
@@ -10,6 +10,7 @@ pub struct Interaction {
|
||||
pub doc: Arc<Document>,
|
||||
/// The selection the previews start from (shared, so a preview frame copies nothing).
|
||||
pub selection: Arc<Selection>,
|
||||
pub(crate) active_appearance_item: Option<crate::cmd::appearance::ActiveItem>,
|
||||
pub preview: Option<(String, Value)>,
|
||||
/// The active tool began it (a drag): a command from outside the tool runs as a step of its
|
||||
/// own under it ([`crate::Session::outside_interaction`]). A dialog or a panel that begins an
|
||||
|
||||
@@ -536,6 +536,7 @@ impl Session {
|
||||
}
|
||||
self.clear_deferred_overlay_cache();
|
||||
let paint = self.paint.clone();
|
||||
let active_appearance_item = self.active_appearance_item.clone();
|
||||
let st = self.doc_mut()?;
|
||||
if st.interaction.is_some() {
|
||||
return Ok(());
|
||||
@@ -545,6 +546,7 @@ impl Session {
|
||||
effect: None,
|
||||
doc: st.doc.clone(),
|
||||
selection: Arc::new(st.selection.clone()),
|
||||
active_appearance_item,
|
||||
preview: None,
|
||||
tool: false,
|
||||
paint,
|
||||
@@ -577,7 +579,7 @@ impl Session {
|
||||
// preview starts from the colors the interaction began with; so does a preview with
|
||||
// `defaultsOnly: true`, and one after it.
|
||||
let tool_paints = self.tool_paints(false) || self.tool_paints(true);
|
||||
let (paint, restore_paint) = {
|
||||
let (paint, restore_paint, active_appearance_item) = {
|
||||
let menu = self.menu.clone();
|
||||
let st = self.doc_mut()?;
|
||||
let Some(it) = &mut st.interaction else { return Err(EngineError::Other("no interaction in progress".into())) };
|
||||
@@ -599,6 +601,7 @@ impl Session {
|
||||
|| it.preview.as_ref().is_some_and(|(id, p)| id == "command.batch" || cmd::asks_defaults_only(p))
|
||||
|| it.color_mode_paints.is_some();
|
||||
let paint = it.paint.clone();
|
||||
let active_appearance_item = it.active_appearance_item.clone();
|
||||
it.preview_paint = None;
|
||||
it.color_mode_paints = None;
|
||||
it.deferred_color_mode = None;
|
||||
@@ -615,8 +618,9 @@ impl Session {
|
||||
// undone with it.
|
||||
st.restore_isolation(isolation, &undone);
|
||||
cmd::globaledit::follow_history(st);
|
||||
(paint, restore_paint)
|
||||
(paint, restore_paint, active_appearance_item)
|
||||
};
|
||||
self.active_appearance_item = active_appearance_item;
|
||||
if restore_paint {
|
||||
self.paint = paint.clone();
|
||||
}
|
||||
@@ -782,10 +786,14 @@ impl Session {
|
||||
self.paint = paint;
|
||||
}
|
||||
let menu = self.menu.clone();
|
||||
let active_appearance_item = self.active().and_then(|st| st.interaction.as_ref()).map(|it| it.active_appearance_item.clone());
|
||||
let st = self.doc_mut()?;
|
||||
st.undo_interaction();
|
||||
// Guides locked and slices locked or hidden during the interaction stay deselected.
|
||||
deselect_hidden(&menu, &st.doc, &mut st.selection);
|
||||
if let Some(active_appearance_item) = active_appearance_item {
|
||||
self.active_appearance_item = active_appearance_item;
|
||||
}
|
||||
// A canceled preview's Assign Profile is undone with it.
|
||||
self.sync_front_profiles();
|
||||
// With New Art Has Basic Appearance off, new art takes the appearance of the selection as
|
||||
|
||||
@@ -140,6 +140,9 @@ fn pump_commit(app: &mut VectorcraftApp) {
|
||||
let label = vectorcraft_engine::find_command(spec.command).map_or(spec.command, |command| command.label);
|
||||
let answer = preview.run(app, *previewing, label, spec.command, params);
|
||||
app.addon_dialogs.preview = preview;
|
||||
if spec.command == super::select::points_only::COMMAND && matches!(&answer, Some(Ok(_))) {
|
||||
app.ui.status.clear();
|
||||
}
|
||||
if let (Some(found), Some(answer)) = (spec.found, answer) {
|
||||
host.with(|h| {
|
||||
if let Some(d) = h.get_mut_by_id::<HostedParamDialog>(id) {
|
||||
@@ -166,6 +169,8 @@ fn pump_commit(app: &mut VectorcraftApp) {
|
||||
};
|
||||
if let Err(error) = answer {
|
||||
app.status(error);
|
||||
} else if spec.command == super::select::points_only::COMMAND {
|
||||
app.ui.status.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,28 @@ fn cancel_puts_the_selection_back() {
|
||||
assert_eq!(app.session.doc().unwrap().selection, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeping_segment_ends_clears_the_preview_error() {
|
||||
for previewing in [true, false] {
|
||||
let (mut app, a, _) = app();
|
||||
app.run("select.segments", json!({"id": a.0, "segments": [[0, 0]]})).unwrap();
|
||||
host::open_item(&mut app, "Selection Tools", "Edit Points Only…");
|
||||
let id = host::dialog_id(&app);
|
||||
host::frame(&mut app);
|
||||
assert!(app.ui.status.contains("no anchor points are selected"), "{}", app.ui.status);
|
||||
host::set(&app, id, "segmentEnds", json!(true));
|
||||
if previewing {
|
||||
host::frame(&mut app);
|
||||
assert!(app.ui.status.is_empty(), "{}", app.ui.status);
|
||||
assert_eq!(points(&app, a), (Some(refs(&[(0, 0), (0, 1)])), false));
|
||||
}
|
||||
assert!(host::confirm(&app, id));
|
||||
host::frame(&mut app);
|
||||
assert!(app.ui.status.is_empty(), "{}", app.ui.status);
|
||||
assert!(!app.any_dialog_open());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ok_with_nothing_to_keep_says_why_and_leaves_the_selection() {
|
||||
let (mut app, a, _) = app();
|
||||
|
||||
Reference in new issue
Block a user