From 43022b6a9e2ccb51293a0904d75608608c405b57 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 15:52:24 -0800 Subject: [PATCH 1/4] Layers: isolation mode lists only the isolated art In isolation mode the Layers panel lists the isolated layer, sublayer, group or object as its top row, with the open rows inside it, and lists every layer again when isolation mode ends. The help page describes the panel showing only the isolated art (https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=212); which row heads the list, and the rules below, are VectorCraft's own. - Entering isolation mode opens the isolated row; leaving it scrolls back to that row. Search and Filter look only inside it. - Nothing is dropped beside the isolated row or into the empty space under the rows, so a drag cannot move art out of the isolated art. - Rows highlighted outside the isolated art are no longer highlighted. - With no row highlighted, Delete Selection is off and the trash returns an error instead of deleting a current layer outside the isolated art. - New Layer, New Sublayer and Duplicate (panel menu and row context menu) are off while the layer or copy they make would be outside the isolated art. ui.newLayer, and OK in New Layer Options, return "exit isolation mode first" then. - Rename refuses an object outside the isolated art, and Locate Object opens no rows outside it. --- crates/mcp/src/ui_catalog.rs | 6 +- crates/ui-egui/src/dialogs/layer_options.rs | 36 +++- crates/ui-egui/src/menus/ui_commands.rs | 6 +- crates/ui-egui/src/panels/layers.rs | 113 +++++++++--- crates/ui-egui/src/panels/layers/controls.rs | 68 ++++++-- crates/ui-egui/src/panels/layers/model.rs | 38 ++++- crates/ui-egui/src/panels/layers/rows.rs | 14 +- crates/ui-egui/src/panels/layers/tests.rs | 170 ++++++++++++++++++- docs/mcp.md | 7 +- docs/target-app-parity.md | 1 + 10 files changed, 404 insertions(+), 55 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index b6da21331e..1a224d3494 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1061,19 +1061,19 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.layerDelete", "Delete Selection", "", - "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", + "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", ), ( "ui.rename", "Rename", "", - "{id?} open the Layers panel's name field on the row of layer, group or object id, as double-clicking the row's name does (the panel is shown and the layers around the row open): Enter renames it with layer.setProps (one undo step), Escape keeps the name. Without id: the highlighted row when a Layers panel row was clicked last, else the one selected object or group, else the one highlighted row, else the current layer. Several rows or objects, or a row the panel's search, filter or Show Layers Only hides, is an error and nothing opens → {id, name}", + "{id?} open the Layers panel's name field on the row of layer, group or object id, as double-clicking the row's name does (the panel is shown and the layers around the row open): Enter renames it with layer.setProps (one undo step), Escape keeps the name. Without id: the highlighted row when a Layers panel row was clicked last, else the one selected object or group, else the one highlighted row, else the current layer. Several rows or objects, a row the panel's search, filter or Show Layers Only hides, or in isolation mode an object outside the isolated art, is an error and nothing opens → {id, name}", ), ( "ui.newLayer", "New Layer Options…", "Cmd+Alt+L", - "{sublayer?: bool} open Layer Options for a new layer (or a sublayer of the current layer), named and coloured as it would be: dialog `layerOptions` with mode new|newSublayer; OK runs layer.new or layer.newSublayer with the fields", + "{sublayer?: bool} open Layer Options for a new layer (or a sublayer of the current layer), named and coloured as it would be: dialog `layerOptions` with mode new|newSublayer; OK runs layer.new or layer.newSublayer with the fields. In isolation mode, a layer that would be outside the isolated art is an error and nothing opens", ), ( "ui.newArtboard", diff --git a/crates/ui-egui/src/dialogs/layer_options.rs b/crates/ui-egui/src/dialogs/layer_options.rs index d40d61c6f5..ce954a32cd 100644 --- a/crates/ui-egui/src/dialogs/layer_options.rs +++ b/crates/ui-egui/src/dialogs/layer_options.rs @@ -157,9 +157,14 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { } /// `ui.newLayer {sublayer?}`: Layer Options for a new layer (or sublayer), with the name and -/// colour it would get. +/// colour it would get. In isolation mode a layer that would be outside the isolated art, where the +/// Layers panel does not list it, is an error. pub fn open_new(app: &mut VectorcraftApp, p: &Value) -> Result { let st = app.session.active().ok_or("no document open")?; + let sublayer = crate::menus::opt_bool(p, "sublayer")?.unwrap_or(false); + if crate::panels::layers::new_layer_unlisted(st, sublayer, false) { + return Err("exit isolation mode first".into()); + } let mut layers = vec![]; st.doc.walk(|n| { if n.is_layer() { @@ -170,7 +175,6 @@ pub fn open_new(app: &mut VectorcraftApp, p: &Value) -> Result { while layers.contains(&format!("Layer {i}")) { i += 1; } - let sublayer = p.get("sublayer").and_then(Value::as_bool).unwrap_or(false); let color = LayerColor::Preset((layers.len() % LAYER_COLORS.len()) as u8); let name = format!("Layer {i}"); let name = if app.session.prefs.identify_objects_by == "xmlId" { vectorcraft_doc::xml_id::from_object_name(&name) } else { name }; @@ -325,6 +329,17 @@ pub(crate) fn params(d: &Dialog) -> (&'static str, Value) { fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { let (cmd, p) = params(d); + // Isolation mode can start while the dialog is open. + let sublayer = match cmd { + "layer.new" => Some(false), + "layer.newSublayer" => Some(true), + _ => None, + }; + if let Some(sublayer) = sublayer + && app.session.active().is_some_and(|st| crate::panels::layers::new_layer_unlisted(st, sublayer, false)) + { + return Err("exit isolation mode first".into()); + } run_and_close(app, cmd, p) } @@ -611,6 +626,23 @@ mod tests { } } + /// OK in New Layer Options makes no layer outside the isolated art when isolation mode started + /// while the dialog was open. + #[test] + fn new_layer_options_ok_checks_isolation_again() { + let mut app = app(); + let id = |v: Value| v["id"].as_u64().unwrap(); + let rect = id(app.session.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap()); + app.session.execute("select.set", &json!({"ids": [rect]})).unwrap(); + let group = id(app.session.execute("object.group", &json!({})).unwrap()); + app.run("ui.newLayer", json!({})).unwrap(); + app.session.execute("object.isolate", &json!({"id": group})).unwrap(); + draw(&mut app); + let err = super::super::confirm(&mut app).unwrap_err(); + assert!(err.contains("exit isolation mode first"), "{err}"); + assert_eq!(app.session.doc().unwrap().doc.layers.len(), 1); + } + #[test] fn new_layer_options_make_a_layer_and_objects_get_name_show_and_lock() { let mut app = app(); diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 677b804720..d741f488dd 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1062,19 +1062,19 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.layerDelete", "Delete Selection", "", - "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", + "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", ), ( "ui.rename", "Rename", "", - "{id?} open the Layers panel's name field on the row of layer, group or object id, as double-clicking the row's name does (the panel is shown and the layers around the row open): Enter renames it with layer.setProps (one undo step), Escape keeps the name. Without id: the highlighted row when a Layers panel row was clicked last, else the one selected object or group, else the one highlighted row, else the current layer. Several rows or objects, or a row the panel's search, filter or Show Layers Only hides, is an error and nothing opens → {id, name}", + "{id?} open the Layers panel's name field on the row of layer, group or object id, as double-clicking the row's name does (the panel is shown and the layers around the row open): Enter renames it with layer.setProps (one undo step), Escape keeps the name. Without id: the highlighted row when a Layers panel row was clicked last, else the one selected object or group, else the one highlighted row, else the current layer. Several rows or objects, a row the panel's search, filter or Show Layers Only hides, or in isolation mode an object outside the isolated art, is an error and nothing opens → {id, name}", ), ( "ui.newLayer", "New Layer Options…", "Cmd+Alt+L", - "{sublayer?: bool} open Layer Options for a new layer (or a sublayer of the current layer), named and coloured as it would be: dialog `layerOptions` with mode new|newSublayer; OK runs layer.new or layer.newSublayer with the fields", + "{sublayer?: bool} open Layer Options for a new layer (or a sublayer of the current layer), named and coloured as it would be: dialog `layerOptions` with mode new|newSublayer; OK runs layer.new or layer.newSublayer with the fields. In isolation mode, a layer that would be outside the isolated art is an error and nothing opens", ), ( "ui.newArtboard", diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index 6e8c2648fa..b3179c36e8 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -66,13 +66,14 @@ mod model; mod rows; mod thumbs; +pub(crate) use controls::new_layer_unlisted; use controls::{bottom_bar, filter_button}; pub use controls::{delete, expand, menu, set_filter}; pub(crate) use model::shown_name; pub use model::{Filter, ObjectKind, RowState}; #[cfg(test)] use model::{Row, list_rows, painted_name}; -use model::{push_rows, rows_of_doc}; +use model::{isolated_root, push_rows, rows_of_doc}; use rows::{drag_ghost, key, rename_id, resolve_click, row}; #[cfg(test)] use thumbs::THUMBS; @@ -171,6 +172,8 @@ struct View<'a> { column: Option, /// The row to scroll into view. reveal: Option, + /// In isolation mode, the isolated node: the top row, which nothing is dropped beside. + root: Option, /// Preferences › Units › Identify Objects By › XML ID. identify_xml_id: bool, } @@ -197,6 +200,17 @@ pub(crate) const ROW_KEYS: &str = "ly-keys"; pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); show_thumbs_of(app.session.active().map(|st| st.uid)); + // In isolation mode only rows inside the isolated art stay highlighted, since the panel lists + // no others. + if let Some(st) = app.session.active_mut() + && let Some(root) = st.isolation.filter(|i| st.doc.node(*i).is_some()) + { + let doc = st.doc.clone(); + let inside = |r: &NodeId| doc.ancestry(*r).is_some_and(|a| a.contains(&root)); + if !st.layer_rows.iter().all(&inside) { + st.layer_rows.retain(&inside); + } + } let Some(st) = app.session.active() else { return }; // A rename belongs to the document it started in (node ids are per document): drop it when // another document shows, so it can't rename that document's node with the same id. @@ -229,16 +243,37 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { if rows.is_empty() && let Some(layer) = current { - let around = doc.ancestry(layer).unwrap_or_default().split_last().map(|(_, a)| a.to_vec()).unwrap_or_default(); - if let Some(st) = app.session.active_mut() { - for a in around { - st.layers_open.set(a, true); - } - } + open_around(app, &doc, &[layer]); reveal = Some(layer); } ui.data_mut(|d| d.insert_temp(key("seen-current"), current)); } + // Entering isolation mode opens the isolated row, now the top row, and scrolls to it; leaving it + // opens the rows around the row that was isolated and scrolls to that row. Showing another + // document changes neither. + let uid = app.session.active().map(|st| st.uid); + let isolated = app.session.active().and_then(|st| st.isolation).filter(|i| doc.node(*i).is_some()); + let seen_isolated: Option<(Option, Option)> = ui.data(|d| d.get_temp(key("seen-isolation"))); + if seen_isolated != Some((uid, isolated)) { + let was = seen_isolated.filter(|(u, _)| *u == uid).and_then(|(_, i)| i); + if seen_isolated.is_none_or(|(u, _)| u == uid) { + match isolated { + Some(root) => { + if let Some(st) = app.session.active_mut() { + st.layers_open.set(root, true); + } + reveal = Some(root); + } + None => { + if let Some(was) = was.filter(|i| doc.node(*i).is_some()) { + open_around(app, &doc, &[was]); + reveal = Some(was); + } + } + } + } + ui.data_mut(|d| d.insert_temp(key("seen-isolation"), (uid, isolated))); + } // With Locate Selected Objects on, an object selected anew outside the panel (below). let located = newly_selected(app, ui).filter(|_| !highlighted); // Search All, and the Filter button at its right. @@ -257,7 +292,9 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { // search or the filter can leave it out): those rows open, and its row is revealed instead of // the row revealed above. Otherwise nothing opens. let located = located.filter(|id| { - app.session.active().is_some_and(|st| listed_when_opened(&doc, &st.layers_open, &app.ui.layers_panel, &query, &app.ui.layers_filter, *id)) + app.session + .active() + .is_some_and(|st| listed_when_opened(&doc, st.isolation, &st.layers_open, &app.ui.layers_panel, &query, &app.ui.layers_filter, *id)) }); if let Some(id) = located { open_around(app, &doc, &[id]); @@ -281,6 +318,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { h: app.ui.layers_panel.row(), column: ui.data(|d| d.get_temp(key("column"))), reveal, + root: st.isolation.and_then(|i| isolated_root(&doc, i)).map(|(n, ..)| n.id), identify_xml_id: app.session.prefs.identify_objects_by == "xmlId", }; let mut out = Out::default(); @@ -330,10 +368,11 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { // The column drag: live while it lasts, one undo step when the button is released. let released = ui.input(|i| i.pointer.any_released()); // Layers dragged into the empty space under the last row go below the bottom layer (there is - // no row there to take the drop). + // no row there to take the drop), except in isolation mode, where that layer is not listed. let below = list_rect.top() - scrolled.inner.state.clamped_offset().y + list.len() as f32 * view.h; if query.is_empty() && !app.ui.layers_filter.is_on() + && view.root.is_none() && let Some(drag) = egui::DragAndDrop::payload::(ui.ctx()) && let LayersDrag::Rows(ids) = &*drag && let Some(bottom) = doc.layers.first() @@ -444,8 +483,9 @@ fn search_query(ctx: &egui::Context) -> String { /// `id`, as double-clicking the row's name does: Enter renames it (`layer.setProps`, one undo /// step), Escape leaves the name as it was. Without `id`, the row Rename names is the Layers /// panel's highlighted row when a row was clicked last, else the one selected object or group, -/// else the one highlighted row, else the current layer. Several of them, or a row the panel's -/// search, filter or Show Layers Only leaves out, is an error that opens nothing. +/// else the one highlighted row, else the current layer. Several of them, a row the panel's +/// search, filter or Show Layers Only leaves out, or in isolation mode an object outside the +/// isolated art, is an error that opens nothing. pub fn rename(app: &mut VectorcraftApp, p: &Value) -> Result { let ctx = app.ui_ctx.clone().ok_or("the Layers panel is not shown")?; let st = app.session.active().ok_or("no document open")?; @@ -473,7 +513,10 @@ pub fn rename(app: &mut VectorcraftApp, p: &Value) -> Result { }; let doc = st.doc.clone(); let node = doc.node(id).ok_or("no such layer or object")?; - if !listed_when_opened(&doc, &st.layers_open, &app.ui.layers_panel, &search_query(&ctx), &app.ui.layers_filter, id) { + if st.isolation.and_then(|i| isolated_root(&doc, i)).is_some_and(|(root, ..)| !doc.ancestry(id).is_some_and(|a| a.contains(&root.id))) { + return Err("the object is outside the isolated group".into()); + } + if !listed_when_opened(&doc, st.isolation, &st.layers_open, &app.ui.layers_panel, &search_query(&ctx), &app.ui.layers_filter, id) { return Err("the Layers panel's search, filter or Show Layers Only hides its row".into()); } let name = node.identify_label(app.session.prefs.identify_objects_by == "xmlId"); @@ -487,10 +530,19 @@ pub fn rename(app: &mut VectorcraftApp, p: &Value) -> Result { Ok(json!({ "id": id.0, "name": name })) } -/// Open the layers and groups around rows `ids`. +/// Open the layers and groups around rows `ids`. In isolation mode only those from the isolated +/// row down open, and nothing opens for a row outside it. fn open_around(app: &mut VectorcraftApp, doc: &Document, ids: &[NodeId]) { - let around: Vec = - ids.iter().flat_map(|r| doc.ancestry(*r).unwrap_or_default().split_last().map(|(_, a)| a.to_vec()).unwrap_or_default()).collect(); + let root = app.session.active().and_then(|st| st.isolation).filter(|i| doc.node(*i).is_some()); + let around: Vec = ids + .iter() + .flat_map(|r| { + let ancestry = doc.ancestry(*r).unwrap_or_default(); + let from = root.map_or(Some(0), |i| ancestry.iter().position(|a| *a == i)); + let parents = ancestry.split_last().map(|(_, a)| a.to_vec()).unwrap_or_default(); + from.map(|f| parents.into_iter().skip(f).collect::>()).unwrap_or_default() + }) + .collect(); if let Some(st) = app.session.active_mut() { for a in around { st.layers_open.set(a, true); @@ -499,20 +551,37 @@ fn open_around(app: &mut VectorcraftApp, doc: &Document, ids: &[NodeId]) { } /// Whether [`list_rows`] gives `id` a row once the layers and groups around it are open as well as -/// `open`. Only the rows of `id`'s top-level layer are listed. -fn listed_when_opened(doc: &Document, open: &OpenRows, opts: &PanelOptions, query: &str, filter: &Filter, id: NodeId) -> bool { +/// `open`, in isolation mode `isolation` (None: outside it). Only the rows of `id`'s top-level +/// layer, or in isolation mode those of the isolated row, are listed. +fn listed_when_opened( + doc: &Document, + isolation: Option, + open: &OpenRows, + opts: &PanelOptions, + query: &str, + filter: &Filter, + id: NodeId, +) -> bool { let Some(ancestry) = doc.ancestry(id) else { return false }; - let Some(layer) = doc.layers.iter().find(|l| ancestry.first() == Some(&l.id)) else { return false }; - if doc.mask_edit.is_some_and(|m| m.layer != layer.id) { - return false; - } let mut open = open.clone(); for a in ancestry.split_last().map(|(_, a)| a).unwrap_or_default() { open.set(*a, true); } let mut rows = vec![]; // Only object rows are looked for, so the guide rows are left out. - push_rows(layer, 0, false, (Color32::PLACEHOLDER, true), (&open, opts, query, filter, &[]), &mut rows); + let cx = (&open, opts, query, filter, &[][..]); + if let Some((root, clip_path, around)) = isolation.and_then(|i| isolated_root(doc, i)) { + if !ancestry.contains(&root.id) { + return false; + } + push_rows(root, 0, clip_path, around, cx, &mut rows); + } else { + let Some(layer) = doc.layers.iter().find(|l| ancestry.first() == Some(&l.id)) else { return false }; + if doc.mask_edit.is_some_and(|m| m.layer != layer.id) { + return false; + } + push_rows(layer, 0, false, (Color32::PLACEHOLDER, true), cx, &mut rows); + } rows.iter().any(|r| r.node.id == id && r.guide.is_none() && !r.spine) } diff --git a/crates/ui-egui/src/panels/layers/controls.rs b/crates/ui-egui/src/panels/layers/controls.rs index 4cea41db75..2bbe376c31 100644 --- a/crates/ui-egui/src/panels/layers/controls.rs +++ b/crates/ui-egui/src/panels/layers/controls.rs @@ -71,9 +71,14 @@ pub(super) fn bottom_bar(app: &mut VectorcraftApp, ui: &mut Ui, view: &View, doc actions.push(("ui.layerDelete".into(), json!({}))); } } + // In isolation mode New Layer and New Sublayer are off while the layer they make would be + // outside the isolated art, where the panel does not list it. + let unlisted = |sublayer: bool, top: bool| app.session.active().is_some_and(|st| new_layer_unlisted(st, sublayer, top)); + let new_layer_ok = !unlisted(false, m.command && !m.alt); + let new_sublayer_ok = !unlisted(true, false); // Create New Layer: Alt asks for its options first, Ctrl/Cmd puts it on top of every layer, // and Ctrl/Cmd+Alt puts it directly below the current layer. - let new_layer = widgets::icon_button(&mut child, "file-plus", tl!("Create New Layer"), false, 24.0); + let new_layer = widgets::icon_button_enabled(&mut child, "file-plus", tl!("Create New Layer"), false, new_layer_ok, 24.0); if new_layer.clicked() { if m.alt && m.command { actions.push(("layer.new".into(), json!({"below": true}))); @@ -90,13 +95,15 @@ pub(super) fn bottom_bar(app: &mut VectorcraftApp, ui: &mut Ui, view: &View, doc let deletes = cmd == "ui.layerDelete"; if let Some(d) = button.dnd_release_payload::() { match &*d { + // A copy of the isolated node would go beside it, outside the isolated art. + LayersDrag::Rows(ids) if !deletes && view.root.is_some_and(|r| ids.contains(&r)) => {} LayersDrag::Rows(ids) => actions.push((cmd.into(), json!({"ids": ids.iter().map(|i| i.0).collect::>()}))), LayersDrag::Guides(guides) if deletes => actions.push(("guide.remove".into(), json!({"indexes": guides}))), _ => {} } } - let over = button.dnd_hover_payload::().is_some_and(|d| match *d { - LayersDrag::Rows(_) => true, + let over = button.dnd_hover_payload::().is_some_and(|d| match &*d { + LayersDrag::Rows(ids) => deletes || !view.root.is_some_and(|r| ids.contains(&r)), LayersDrag::Guides(_) => deletes, LayersDrag::Art => false, }) || (deletes && button.dnd_hover_payload::().is_some_and(|d| matches!(*d, PanelDrag::Appearance(_)))); @@ -106,7 +113,7 @@ pub(super) fn bottom_bar(app: &mut VectorcraftApp, ui: &mut Ui, view: &View, doc } // Create New Sublayer: Alt asks for its options first, and Ctrl/Cmd+Alt puts it under the // layer's contents. - if widgets::icon_button(&mut child, "plus", tl!("Create New Sublayer"), false, 24.0).clicked() { + if widgets::icon_button_enabled(&mut child, "plus", tl!("Create New Sublayer"), false, new_sublayer_ok, 24.0).clicked() { actions.push(match (m.alt, m.command) { (true, true) => ("layer.newSublayer".into(), json!({"bottom": true})), (true, false) => ("ui.newLayer".into(), json!({"sublayer": true})), @@ -128,11 +135,14 @@ type MenuItem<'a> = (&'a str, &'a str, Value, bool, bool); pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { let Some(st) = app.session.active() else { return }; let doc = st.doc.clone(); - let rows = st.highlighted_rows(); + let rows = listed_highlighted_rows(st); let current = st.current_layer(); let has_sel = !st.selection.is_empty(); let isolated = st.isolation.is_some(); - let targets: Vec = if rows.is_empty() { current.into_iter().collect() } else { rows.clone() }; + let targets: Vec = if rows.is_empty() { listed_current_layer(st).into_iter().collect() } else { rows.clone() }; + let (new_layer_ok, new_sublayer_ok) = (!new_layer_unlisted(st, false, false), !new_layer_unlisted(st, true, false)); + // A copy of the isolated node goes beside it, outside the isolated art. + let duplicate_ok = !targets.is_empty() && !st.isolation.is_some_and(|r| targets.contains(&r)); let one_container = match targets.as_slice() { [id] => doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Layer { .. } | NodeKind::Group { .. })), _ => false, @@ -149,9 +159,9 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { } }); let mut items: Vec> = vec![ - Some(("New Layer…", "ui.newLayer", json!({}), true, false)), - Some(("New Sublayer…", "ui.newLayer", json!({"sublayer": true}), current.is_some(), false)), - Some(("Duplicate Selection", "layer.duplicate", json!({}), !targets.is_empty(), false)), + Some(("New Layer…", "ui.newLayer", json!({}), new_layer_ok, false)), + Some(("New Sublayer…", "ui.newLayer", json!({"sublayer": true}), current.is_some() && new_sublayer_ok, false)), + Some(("Duplicate Selection", "layer.duplicate", json!({}), duplicate_ok, false)), Some(("Delete Selection", "ui.layerDelete", json!({}), !targets.is_empty(), false)), Some(("Options for Selection…", "ui.layerOptions", json!({}), !targets.is_empty(), false)), None, @@ -283,7 +293,8 @@ fn save_selection_menu(app: &mut VectorcraftApp, ui: &mut Ui) { /// `ui.layerDelete {ids?|id?, doc?, confirmed?}`: Delete Selection as the Layers panel runs it (the /// trash button, rows dropped on it, the panel menu, Delete and Backspace), on the rows -/// `layer.delete` takes. When a layer or sublayer among them holds art (an object other than a +/// `layer.delete` takes (default: the highlighted rows, else the current layer; in isolation mode a +/// current layer outside the isolated art is an error). When a layer or sublayer among them holds art (an object other than a /// guide, hidden, locked and nested ones included), it asks first: OK deletes those rows, by id, in /// the same document (`doc`, its uid, with `confirmed`); with another document active then, nothing /// is deleted. Other rows, and rows `layer.delete` refuses (an unknown id, every top-level layer), @@ -306,7 +317,10 @@ pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result { (Some(v), _) => v.as_array().and_then(|a| a.iter().map(row).collect()), (None, Some(v)) => row(v).map(|id| vec![id]), (None, None) => { - let rows = st.highlighted_rows(); + let rows = listed_highlighted_rows(st); + if rows.is_empty() && st.current_layer().is_some() && listed_current_layer(st).is_none() { + return Err("the object is outside the isolated group".into()); + } Some(if rows.is_empty() { st.current_layer().into_iter().collect() } else { rows }) } }; @@ -327,6 +341,38 @@ pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result { Ok(Value::Null) } +/// Whether `id` is the isolated node or inside it: a row the panel can list. Always true outside +/// isolation mode. +fn in_isolated_art(st: &vectorcraft_engine::DocState, id: NodeId) -> bool { + let root = st.isolation.filter(|i| st.doc.node(*i).is_some()); + root.is_none_or(|r| st.doc.ancestry(id).is_some_and(|a| a.contains(&r))) +} + +/// The highlighted rows the panel lists: in isolation mode only those in the isolated art. +fn listed_highlighted_rows(st: &vectorcraft_engine::DocState) -> Vec { + st.highlighted_rows().into_iter().filter(|id| in_isolated_art(st, *id)).collect() +} + +/// The current layer, which the panel's commands act on when no row is highlighted. In isolation +/// mode it is None unless the layer is inside the isolated art, the only art the panel lists. +fn listed_current_layer(st: &vectorcraft_engine::DocState) -> Option { + st.current_layer().filter(|l| in_isolated_art(st, *l)) +} + +/// In isolation mode, whether the layer that New Layer (`sublayer` false; `top`: on top of every +/// layer) or New Sublayer makes would be outside the isolated art, where the panel does not list +/// it. New Layer goes beside the current layer, New Sublayer into the layer of the last highlighted +/// row, else into the current layer, as `layer.new` and `layer.newSublayer` place them. +pub(crate) fn new_layer_unlisted(st: &vectorcraft_engine::DocState, sublayer: bool, top: bool) -> bool { + let Some(root) = st.isolation.filter(|i| st.doc.node(*i).is_some()) else { return false }; + if sublayer { + let row = st.highlighted_rows().last().and_then(|r| st.doc.layer_containing(*r)); + !row.or(st.current_layer()).is_some_and(|p| in_isolated_art(st, p)) + } else { + top || !st.current_layer().is_some_and(|c| c != root && in_isolated_art(st, c)) + } +} + /// The rows among `nodes` (and the rows inside them) that are in `listed` and not inside another /// listed row, top-level first. fn row_roots<'a>(nodes: &'a [Arc], listed: &HashSet, out: &mut Vec<&'a Node>) { diff --git a/crates/ui-egui/src/panels/layers/model.rs b/crates/ui-egui/src/panels/layers/model.rs index 428149d776..35a999a3c8 100644 --- a/crates/ui-egui/src/panels/layers/model.rs +++ b/crates/ui-egui/src/panels/layers/model.rs @@ -217,6 +217,7 @@ pub(super) fn parse_names(p: &Value, key: &str, all: &[(T, struct RowsKey { uid: u64, revision: u64, + isolation: Option, open: u64, layers_only: bool, query: String, @@ -224,19 +225,45 @@ struct RowsKey { } /// The rows the panel shows, top down: the layers (only the opacity mask's while one is edited) -/// with the rows of the open ones inside them. A search or a filter shows every row whose name -/// contains `query` (lowercase) and that `filter` keeps, and every row holding one. -pub(super) fn list_rows(doc: &Document, open: &OpenRows, opts: &PanelOptions, query: &str, filter: &Filter) -> Vec { +/// with the rows of the open ones inside them. In isolation mode (`isolation`) only the isolated +/// layer, sublayer, group or object is listed, as the top row, with the open rows inside it. A +/// search or a filter shows every row whose name contains `query` (lowercase) and that `filter` +/// keeps, and every row holding one. +pub(super) fn list_rows(doc: &Document, isolation: Option, open: &OpenRows, opts: &PanelOptions, query: &str, filter: &Filter) -> Vec { let mask_layer = doc.mask_edit.map(|m| m.layer); // The ruler guides' ids by `guide.list` index, listed once for every layer. let guides: Vec = doc.ruler_guides().into_iter().filter_map(|g| g.id).collect(); let mut out = vec![]; + if let Some((root, clip_path, around)) = isolation.and_then(|i| isolated_root(doc, i)) { + push_rows(root, 0, clip_path, around, (open, opts, query, filter, &guides), &mut out); + return out; + } for l in doc.layers.iter().rev().filter(|l| mask_layer.is_none_or(|m| m == l.id)) { push_rows(l, 0, false, (Color32::PLACEHOLDER, true), (open, opts, query, filter, &guides), &mut out); } out } +/// The isolated node `id`, which heads the rows in isolation mode, with what [`push_rows`] takes +/// for it: whether it is its parent's clipping path, and the color of the layer holding it and +/// whether the layers and groups around it are visible. None when `id` is not in `doc`. +pub(super) fn isolated_root(doc: &Document, id: NodeId) -> Option<(&Arc, bool, (Color32, bool))> { + let path = doc.index_path(id)?; + let (first, rest) = path.split_first()?; + let mut cur = doc.layers.get(*first)?; + let (mut clip_path, mut colour, mut shown) = (false, Color32::PLACEHOLDER, true); + for &i in rest { + if let NodeKind::Layer { color, .. } = &cur.kind { + let [r, g, b] = color.rgb(); + colour = Color32::from_rgb(r, g, b); + } + shown &= cur.visible; + clip_path = i == 0 && cur.clips(); + cur = cur.children()?.get(i)?; + } + Some((cur, clip_path, (colour, shown))) +} + /// Add the rows of `n` and those open inside it to `out`; `(colour, shown)` are those of what holds /// it (the layer's colour, and whether it is visible). The last item of `cx` is the document's /// ruler guide ids by `guide.list` index. @@ -325,11 +352,12 @@ pub(super) fn push_rows( } /// The rows of the active document as [`list_rows`] lists them, listed again only when the -/// document, its open rows, the search, the filter or Show Layers Only changed. +/// document, isolation mode, its open rows, the search, the filter or Show Layers Only changed. pub(super) fn rows_of_doc(ui: &Ui, st: &vectorcraft_engine::DocState, opts: &PanelOptions, query: &str, filter: &Filter) -> Arc> { let now = RowsKey { uid: st.uid, revision: st.revision, + isolation: st.isolation, open: st.layers_open.generation(), layers_only: opts.layers_only, query: query.to_string(), @@ -341,7 +369,7 @@ pub(super) fn rows_of_doc(ui: &Ui, st: &vectorcraft_engine::DocState, opts: &Pan { return rows; } - let rows = Arc::new(list_rows(&st.doc, &st.layers_open, opts, query, filter)); + let rows = Arc::new(list_rows(&st.doc, st.isolation, &st.layers_open, opts, query, filter)); ui.data_mut(|d| d.insert_temp(id, (now, rows.clone()))); rows } diff --git a/crates/ui-egui/src/panels/layers/rows.rs b/crates/ui-egui/src/panels/layers/rows.rs index 62e32f1097..dd8bd210f8 100644 --- a/crates/ui-egui/src/panels/layers/rows.rs +++ b/crates/ui-egui/src/panels/layers/rows.rs @@ -476,7 +476,9 @@ fn row_context_menu(ui: &mut Ui, view: &View, n: &Node, collect_ids: &[u64], out } }; let dup_label = if is_multi { tl!("Duplicate Selection").to_string() } else { format!("{} \"{display}\"", tl!("Duplicate")) }; - if widgets::menu_item_name(ui, &dup_label, true, false) { + // A copy of the isolated node goes beside it, outside the isolated art. + let dup_enabled = !view.root.is_some_and(|r| collect_ids.contains(&r.0)); + if widgets::menu_item_name(ui, &dup_label, dup_enabled, false) { out.actions.push(("layer.duplicate".into(), json!({ "ids": collect_ids }))); ui.close(); } @@ -689,6 +691,16 @@ fn drop_target(ui: &Ui, view: &View, n: &Node, r: egui::Rect, indent: f32, open: LayersDrag::Rows(_) if rel < 0.5 => Place::Above, LayersDrag::Rows(_) | LayersDrag::Guides(_) => Place::Below, }; + // In isolation mode the isolated row takes a drop only inside it, so nothing leaves the isolated + // art or lands beside it. + let place = if view.root == Some(n.id) { + if !inside { + return; + } + Place::Inside + } else { + place + }; // Beside a member of an Intertwine group (or a row in one) only what can be intertwined goes. if place != Place::Inside && doc.parent_of(n.id).is_some_and(|p| in_intertwine(doc, p)) diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index 2570e77df7..61ec9b7f2e 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -763,6 +763,163 @@ fn masks_underline_dashed_and_mask_editing_lists_only_the_mask() { assert!(after > before + 1, "a dashed underline: {before} → {after}"); } +// ---- isolation mode ---- + +/// The object rows [`list_rows`] lists for the active document, top down, with their depths. +fn listed_ids(app: &VectorcraftApp) -> Vec<(NodeId, usize)> { + let st = app.session.active().unwrap(); + let rows = list_rows(&st.doc, st.isolation, &st.layers_open, &PanelOptions::default(), "", &Filter::default()); + rows.iter().filter(|r| r.guide.is_none() && !r.spine).map(|r| (r.node.id, r.depth)).collect() +} + +/// In isolation mode the panel lists only the isolated sublayer, group or object, as the top row +/// with the open rows inside it; the other layers and groups are listed again when it ends. +#[test] +fn isolation_lists_only_the_isolated_art_and_exit_lists_every_layer_again() { + let (mut app, [layer, sub, g, b, a, c]) = nested(); + let run = |app: &mut VectorcraftApp, id: &str, p: serde_json::Value| app.session.execute(id, &p).unwrap(); + let top = NodeId(run(&mut app, "layer.new", json!({"top": true, "name": "Top"}))["id"].as_u64().unwrap()); + let all = vec![(top, 0), (layer, 0), (sub, 1), (g, 2), (b, 3), (a, 2), (c, 1)]; + assert_eq!(listed_ids(&app), all); + run(&mut app, "object.isolate", json!({"id": g.0})); + assert_eq!(listed_ids(&app), [(g, 0), (b, 1)], "the group and its art"); + run(&mut app, "object.exitIsolation", json!({})); + assert_eq!(listed_ids(&app), all, "every layer again"); + run(&mut app, "object.isolate", json!({"id": sub.0})); + assert_eq!(listed_ids(&app), [(sub, 0), (g, 1), (b, 2), (a, 1)], "the sublayer and its art"); + // Isolating an object inside lists that object alone. + run(&mut app, "object.isolate", json!({"id": a.0})); + assert_eq!(listed_ids(&app), [(a, 0)]); + run(&mut app, "object.exitIsolation", json!({})); + assert_eq!(listed_ids(&app), all); + // A closed isolated group lists its own row alone, and an isolated object that is gone leaves + // every layer listed. + run(&mut app, "object.isolate", json!({"id": g.0})); + app.session.active_mut().unwrap().layers_open.set(g, false); + assert_eq!(listed_ids(&app), [(g, 0)]); + app.session.active_mut().unwrap().isolation = Some(NodeId(999_999)); + assert_eq!(listed_ids(&app), [(top, 0), (layer, 0), (sub, 1), (g, 2), (a, 2), (c, 1)]); +} + +/// Entering isolation mode opens the isolated row and leaving it lists every row again; a drop +/// beside the isolated row or into the empty space under it moves nothing out of the isolated art. +#[test] +fn isolation_opens_the_isolated_row_and_keeps_drops_inside_it() { + let (mut app, [layer, sub, g, _, a, _]) = nested(); + let ctx = egui::Context::default(); + let parent = |app: &VectorcraftApp, id: NodeId| app.session.active().unwrap().doc.parent_of(id); + let (circles, _) = frame(&mut app, &ctx, vec![], false); + assert_eq!(circles.len(), 6); + app.session.active_mut().unwrap().layers_open.set(sub, false); + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + // Rows: Sub, g, b, a. + let (circles, _) = frame(&mut app, &ctx, vec![], false); + assert_eq!(circles.len(), 4, "the sublayer's row opens"); + // Rectangle a onto the upper edge of the sublayer's row: not above it, outside the sublayer. + drag(&mut app, &ctx, egui::pos2(150.0, circles[3].y), egui::pos2(150.0, circles[0].y - ROW_MEDIUM * 0.4), false); + assert_eq!(parent(&app, a), Some(sub)); + // The sublayer into the empty space under the rows: it stays in Layer 1. + let (circles, _) = frame(&mut app, &ctx, vec![], false); + assert_eq!(circles.len(), 4); + drag(&mut app, &ctx, egui::pos2(150.0, circles[0].y), egui::pos2(150.0, circles[3].y + 3.0 * ROW_MEDIUM), false); + assert_eq!(parent(&app, sub), Some(layer)); + // Rectangle a onto the middle of the group's row: into it. + let (circles, _) = frame(&mut app, &ctx, vec![], false); + let at = |app: &VectorcraftApp, id: NodeId| circles[listed_ids(app).iter().position(|(n, _)| *n == id).unwrap()]; + let (from, to) = (at(&app, a), at(&app, g)); + drag(&mut app, &ctx, egui::pos2(150.0, from.y), egui::pos2(150.0, to.y), false); + assert_eq!(parent(&app, a), Some(g)); + app.session.execute("object.exitIsolation", &json!({})).unwrap(); + let (circles, _) = frame(&mut app, &ctx, vec![], false); + assert_eq!(circles.len(), 6, "every row again"); +} + +/// In isolation mode the rows outside the isolated art are no longer highlighted, so Delete and the +/// trash in the panel act only on rows it lists. +#[test] +fn isolation_drops_highlights_outside_the_isolated_art() { + let (mut app, [_, sub, _, b, _, c]) = nested(); + let ctx = egui::Context::default(); + app.session.execute("layer.highlight", &json!({"ids": [c.0, b.0], "mode": "set"})).unwrap(); + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + frame(&mut app, &ctx, vec![], false); + assert_eq!(rows_of(&app), [b], "the rectangle on Layer 1, outside the sublayer, is let go"); +} + +/// In isolation mode Rename and the rows opened around a located object stay inside the isolated +/// row: an object outside it has no row to rename, and opens no rows. +#[test] +fn isolation_keeps_rename_and_locate_to_the_rows_listed() { + let (mut app, [layer, sub, g, b, _, c]) = nested(); + let ctx = egui::Context::default(); + app.ui_ctx = Some(ctx.clone()); + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + let err = app.run("ui.rename", json!({"id": c.0})).unwrap_err(); + assert!(err.contains("the object is outside the isolated group"), "{err}"); + assert_eq!(app.run("ui.rename", json!({"id": b.0})).unwrap()["id"], json!(b.0)); + { + let st = app.session.active().unwrap(); + let listed = |id| listed_when_opened(&st.doc, st.isolation, &st.layers_open, &PanelOptions::default(), "", &Filter::default(), id); + assert_eq!([layer, sub, g, b, c].map(listed), [false, true, true, true, false]); + } + let st = app.session.active_mut().unwrap(); + st.layers_open.set(layer, false); + st.layers_open.set(g, false); + let doc = st.doc.clone(); + open_around(&mut app, &doc, &[c]); + open_around(&mut app, &doc, &[b]); + let open = &app.session.active().unwrap().layers_open; + assert!(open.contains(g), "the group inside the sublayer opens"); + assert!(!open.contains(layer), "the layer around the sublayer stays closed"); +} + +/// In isolation mode, with no row highlighted, Delete Selection and the trash do not delete the +/// current layer when it is outside the isolated art, where the panel does not list it. +#[test] +fn isolation_keeps_delete_to_the_rows_listed() { + let (mut app, [layer, sub, g, b, a, c]) = nested(); + app.session.execute("object.isolate", &json!({"id": g.0})).unwrap(); + // A row left highlighted outside the isolated group before the panel shows again. + let st = app.session.active_mut().unwrap(); + st.layer_rows = vec![c]; + let current = st.current_layer().unwrap(); + assert!([layer, sub].contains(¤t), "the current layer holds the isolated group"); + let err = app.run("ui.layerDelete", json!({})).unwrap_err(); + assert!(err.contains("the object is outside the isolated group"), "{err}"); + let doc = &app.session.active().unwrap().doc; + assert!([layer, sub, g, b, a, c].iter().all(|id| doc.node(*id).is_some()), "nothing was deleted"); + app.session.active_mut().unwrap().layer_rows = vec![b]; + app.run("ui.layerDelete", json!({})).unwrap(); + let doc = &app.session.active().unwrap().doc; + assert!(doc.node(b).is_none(), "a highlighted row inside the isolated group is deleted"); + assert!(doc.node(a).is_some() && doc.node(c).is_some()); +} + +/// In isolation mode New Layer and New Sublayer are off, and `ui.newLayer` is an error, while the +/// layer they make would be outside the isolated art; a sublayer of an isolated sublayer is listed. +#[test] +fn isolation_keeps_new_layers_to_the_rows_listed() { + let (mut app, [_, sub, g, ..]) = nested(); + app.session.execute("object.isolate", &json!({"id": g.0})).unwrap(); + let st = app.session.active().unwrap(); + assert_eq!([(false, false), (true, false), (false, true)].map(|(s, t)| new_layer_unlisted(st, s, t)), [true; 3]); + for p in [json!({}), json!({"sublayer": true})] { + let err = app.run("ui.newLayer", p).unwrap_err(); + assert!(err.contains("exit isolation mode first"), "{err}"); + } + assert!(app.ui.dialog.is_none()); + app.session.execute("object.exitIsolation", &json!({})).unwrap(); + app.session.execute("layer.setCurrent", &json!({"id": sub.0})).unwrap(); + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + let st = app.session.active().unwrap(); + assert!(new_layer_unlisted(st, false, false), "a new layer would go beside the isolated sublayer"); + assert!(!new_layer_unlisted(st, true, false), "a new sublayer goes inside it"); + app.run("ui.newLayer", json!({"sublayer": true})).unwrap(); + assert!(app.ui.dialog.is_some()); + app.session.execute("object.exitIsolation", &json!({})).unwrap(); + assert!(!new_layer_unlisted(app.session.active().unwrap(), false, true)); +} + // ---- rows at every depth (layers, sublayers, groups, objects) ---- /// Layer 1 holding rectangle `c` and a sublayer holding rectangle `a` and a group of @@ -901,7 +1058,8 @@ fn guide_rows_have_their_own_eye_and_lock() { }; let dimmed = |app: &VectorcraftApp| { let st = app.session.active().unwrap(); - list_rows(&st.doc, &st.layers_open, &PanelOptions::default(), "", &Filter::default()).iter().find(|r| r.guide.is_some()).unwrap().dim + let rows = list_rows(&st.doc, st.isolation, &st.layers_open, &PanelOptions::default(), "", &Filter::default()); + rows.iter().find(|r| r.guide.is_some()).unwrap().dim }; click_with(&mut app, &ctx, name, egui::Modifiers::NONE); assert_eq!(selected(&app), [guide]); @@ -1295,7 +1453,7 @@ fn kinds() -> (VectorcraftApp, HashMap<&'static str, NodeId>) { /// for a guide's row). fn listed(app: &VectorcraftApp, ids: &HashMap<&'static str, NodeId>, query: &str, filter: &Filter) -> Vec<&'static str> { let st = app.session.active().unwrap(); - let rows = list_rows(&st.doc, &st.layers_open, &PanelOptions::default(), query, filter); + let rows = list_rows(&st.doc, st.isolation, &st.layers_open, &PanelOptions::default(), query, filter); let name = |r: &Row| match r.guide { Some(_) => "ruler guide", None => ids.iter().find(|(_, id)| **id == r.node.id).map_or("?", |(name, _)| *name), @@ -2608,10 +2766,10 @@ fn a_blends_spine_is_a_row_below_its_keys_that_selects_the_blend() { run(&mut app, "select.none", json!({})); expand(&mut app, &json!({})).unwrap(); let st = app.session.active().unwrap(); - let rows = list_rows(&st.doc, &st.layers_open, &PanelOptions::default(), "", &Filter::default()); + let rows = list_rows(&st.doc, st.isolation, &st.layers_open, &PanelOptions::default(), "", &Filter::default()); let kinds: Vec<(u64, bool)> = rows.iter().map(|r| (r.node.id.0, r.spine)).collect(); assert_eq!(kinds[1..], [(blend.0, false), (b, false), (a, false), (blend.0, true)], "the spine row comes last in the blend"); - let rows = list_rows(&st.doc, &st.layers_open, &PanelOptions::default(), "rect", &Filter::default()); + let rows = list_rows(&st.doc, st.isolation, &st.layers_open, &PanelOptions::default(), "rect", &Filter::default()); assert!(!rows.iter().any(|r| r.spine), "no spine row while searching"); // Rows top down: the layer, the blend, both keys (with target circles), then the spine. let ctx = egui::Context::default(); @@ -2642,7 +2800,7 @@ fn ruler_guide_nodes_get_no_object_row() { let g = Node::new(doc.alloc_id(), NodeKind::RulerGuide { vertical: true, pos: 20.0, artboard: None }); doc.insert(Some(l), usize::MAX, g).unwrap(); } - let rows = list_rows(&st.doc, &st.layers_open, &PanelOptions::default(), "", &Filter::default()); + let rows = list_rows(&st.doc, st.isolation, &st.layers_open, &PanelOptions::default(), "", &Filter::default()); let ids: Vec = rows.iter().filter(|r| r.guide.is_none()).map(|r| r.node.id).collect(); assert_eq!(ids, [second, first, rect]); // Each guide is a guide row of its layer instead. @@ -2668,7 +2826,7 @@ fn guide_rows_list_by_index_whatever_the_node_order() { doc.move_node(first, Some(layer), usize::MAX).unwrap(); let kids: Vec = doc.layers[0].children().unwrap().iter().map(|c| c.id).collect(); assert_eq!(kids.last(), Some(&first)); - let rows = list_rows(&st.doc, &st.layers_open, &PanelOptions::default(), "", &Filter::default()); + let rows = list_rows(&st.doc, st.isolation, &st.layers_open, &PanelOptions::default(), "", &Filter::default()); let indexes: Vec = rows.iter().filter_map(|r| r.guide).collect(); assert_eq!(indexes, [2, 1, 0]); } diff --git a/docs/mcp.md b/docs/mcp.md index 4c1b661f42..7055eb35d1 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5428,7 +5428,8 @@ and `layerRows`, the rows highlighted in the panel. Selection, and Delete or Backspace on highlighted rows: when a layer or sublayer among the rows holds art, hidden, locked or nested art included, dialog `confirm` asks "Delete this layer and its artwork?" for one layer, else "Delete the selected items and their artwork?"; OK deletes the rows it asked about in that document, one undo step, and - Cancel keeps them; an empty layer, a layer with only guides, and groups or objects alone are deleted at once), + Cancel keeps them; an empty layer, a layer with only guides, and groups or objects alone are deleted at once; in + isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted), `layer.locate {id?}` (highlights the selected object's row; the panel opens the rows around it) and `layer.clippingMask.toggle`. - **Panel menu**: `layer.duplicate {ids?}`, `layer.merge {ids?}` (into the layer highlighted last, keeping the @@ -5450,7 +5451,9 @@ and `layerRows`, the rows highlighted in the panel. {sublayer?}` open Layer Options (dialog `layerOptions`: name, color, template, locked, visible, printable, preview, dimImages, dimPercent; OK is one undo step; `ui.dialog.set` of `template` also sets `locked` and `dimImages`, as the checkbox does, except a Dim Images set before it; for several `ids` the dialog shows the first row's settings, and OK sends only the fields set with a - control or `ui.dialog.set`; Cmd/Ctrl+Alt+L runs `ui.newLayer` for a new layer), `ui.layersPanelOptions` opens Panel Options (`layersPanelOptions`: + control or `ui.dialog.set`; Cmd/Ctrl+Alt+L runs `ui.newLayer` for a new layer; in isolation mode `ui.newLayer` for a + layer that would be outside the isolated art is an error, and the Layers panel's New Layer and New Sublayer are off + then), `ui.layersPanelOptions` opens Panel Options (`layersPanelOptions`: layersOnly, locateSelected, rowSize small|medium|large|other, otherSize, thumbLayers, thumbGroups, thumbObjects), and `ui.layersExpand {ids?, open?}` opens or closes rows as their triangles do (Alt-click: everything inside). With `locateSelected` on (Locate Selected Objects, off by default), when the last selected object changes on the canvas diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ef83de54ad..8e9f13d7ff 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1148,6 +1148,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - The canvas context menu has Isolate Selected Path (`object.isolate`) when the selection is one path, a path selected inside a group or a compound path included, as the [help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=324) lists it beside Isolate Selected Group. As VectorCraft's own rule, neither item shows for two or more objects, or for an object `object.isolate` refuses: a hidden or locked object, one in a hidden or locked group or layer, a guide while Lock Guides is on, and, while a symbol is edited, an object outside the symbol's art (`single_path_context_item_enters_isolation`, `isolation_context_item_follows_selected_kind`, `isolation_context_item_skips_objects_that_cannot_be_isolated`). - While an opacity mask is edited, Exit Isolation Mode (Esc, the isolation bar's back arrow, the Control bar's button, and the Layers panel menu's and canvas context menu's Exit Isolation Mode) leaves mask editing as Stop Editing Opacity Mask does, in one undo step: the mask keeps the edits, and the masked object is selected. While a pattern is edited, the Exit Isolation Mode item of the Layers panel menu and of the canvas context menu saves the pattern and leaves pattern editing, as Done does. - A click anywhere on the isolation bar, the isolated object's name included, outside its back arrow, the breadcrumbs of the levels above and its buttons leaves isolation mode altogether, nested isolation included, as Exit Isolation Mode does ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs4/illustrator_cs4_help.pdf#page=207)). As VectorCraft's own rules, the click stops editing an opacity mask, leaves symbol editing mode even while a group inside the symbol's art is isolated, together with the isolation the mode was entered from, and does nothing while a pattern is edited; a drag across the bar does not leave (`isolation_bar_background_click_exits_nested_isolation`). + - In isolation mode the Layers panel lists only the art of the isolated layer, sublayer or group, and lists the other layers and groups again when isolation mode ends ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=212)). As VectorCraft's own rules, the isolated layer, sublayer, group or object is the top row and opens on entering, the panel scrolls back to its row on leaving, search and filter look only inside it, nothing is dropped beside its row or into the empty space under the rows, Rename and Locate Object open no rows outside it, and rows highlighted outside it are no longer highlighted. With no row highlighted, Delete Selection and the trash do not delete a current layer outside it. New Layer, New Sublayer and Duplicate (in the panel menu and a row's context menu) are off, and OK in New Layer Options is an error, while the layer or copy they make would be outside it (`isolation_lists_only_the_isolated_art_and_exit_lists_every_layer_again`, `isolation_opens_the_isolated_row_and_keeps_drops_inside_it`, `isolation_drops_highlights_outside_the_isolated_art`, `isolation_keeps_rename_and_locate_to_the_rows_listed`, `isolation_keeps_delete_to_the_rows_listed`, `isolation_keeps_new_layers_to_the_rows_listed`, `new_layer_options_ok_checks_isolation_again`). - Numeric spinner arrows keep stepping while held with the mouse past the click timeout and stop on release (#6307; `a_held_spinner_arrow_repeats`). - Object › Vector Halftone keeps the selection box and hides selection marks on the temporary dots during Preview; turning Preview off or cancelling restores the original selection marks (#6369). - Tab shows and hides the panels (in the Type tool it types a tab) without moving the keyboard focus onto a field, so the next shortcut or letter still works; in dialogs and panel fields it moves between fields, one press each — a numeric field's scrub label is not a tab stop of its own, and the Transform panel's, Properties panel's and Control bar's W/H link comes after the fields it sits between (`one_tab_moves_from_a_field_to_the_next`). A field's up/down spinner, the chevron that opens its presets (Stroke Weight, font size, Rotate, Export for Screens' scale) and the Transparency row's opacity slider chevron are not tab stops either. Alt+↓ with no other modifier in a field with presets opens them with the keyboard focus on the chosen one, instead of stepping the field down; Enter picks the focused preset without pressing a dialog's OK, and after a pick or Escape the field has the keyboard focus again (`tab_goes_from_field_to_field_past_the_spinner_and_the_preset_chevron`, `tab_goes_from_the_opacity_field_past_its_slider_chevron`, `alt_down_opens_a_fields_presets_for_the_keyboard`, `escape_closes_a_fields_presets_and_returns_to_the_field`). From 6561c30c8f1907e6689823b43ac7079d04373e51 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 17:07:30 -0800 Subject: [PATCH 2/4] Layers: isolation mode keeps menus, drops and Show Layers Only to the isolated art - With Show Layers Only on, an isolated group or object is listed as the top row instead of leaving the panel empty. - Duplicate Selection in the panel menu sends the rows the panel lists, so a highlighted row outside the isolated art is not copied. - In isolation mode the Hide, Outline and Lock Others pairs in the panel menu and the row menu are off, and Alt-clicks on an eye or a lock change nothing. Locate Layer is off while a group or object is isolated. - OK in Delete Selection's question deletes nothing when isolation mode started while it asked and a row it asked about is outside the isolated art. - The isolated row shows no drop place for an Alt-drag onto itself, and a guide is not dropped on a layer outside the isolated art. - Each document's isolation mode is followed on its own, so a document first shown in isolation mode opens its isolated row. - The isolation test steps out of a sublayer one level at a time, as Exit Isolation Mode now does. --- crates/mcp/src/ui_catalog.rs | 4 +- crates/ui-egui/src/menus/ui_commands.rs | 4 +- crates/ui-egui/src/panels/layers.rs | 21 +- crates/ui-egui/src/panels/layers/controls.rs | 32 ++-- crates/ui-egui/src/panels/layers/model.rs | 5 +- crates/ui-egui/src/panels/layers/rows.rs | 41 +++- crates/ui-egui/src/panels/layers/tests.rs | 191 ++++++++++++++++++- docs/mcp.md | 14 +- 8 files changed, 266 insertions(+), 46 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 65efa74c9c..a03e9e8538 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1160,7 +1160,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.layerDelete", "Delete Selection", "", - "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", + "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, or in isolation mode with one of the rows outside the isolated art, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", ), ( "ui.rename", @@ -1172,7 +1172,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.newLayer", "New Layer Options…", "Cmd+Alt+L", - "{sublayer?: bool} open Layer Options for a new layer (or a sublayer of the current layer), named and coloured as it would be: dialog `layerOptions` with mode new|newSublayer; OK runs layer.new or layer.newSublayer with the fields. In isolation mode, a layer that would be outside the isolated art is an error and nothing opens", + "{sublayer?: bool} open Layer Options for a new layer (or a sublayer of the current layer), named and coloured as it would be: dialog `layerOptions` with mode new|newSublayer; OK runs layer.new or layer.newSublayer with the fields. In isolation mode, a layer that would be outside the isolated art is an error and nothing opens; OK checks again, and with isolation mode started since, it returns the same error and makes no layer", ), ( "ui.newArtboard", diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index e65589dd21..6d950c882b 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1161,7 +1161,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.layerDelete", "Delete Selection", "", - "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", + "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, or in isolation mode with one of the rows outside the isolated art, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", ), ( "ui.rename", @@ -1173,7 +1173,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.newLayer", "New Layer Options…", "Cmd+Alt+L", - "{sublayer?: bool} open Layer Options for a new layer (or a sublayer of the current layer), named and coloured as it would be: dialog `layerOptions` with mode new|newSublayer; OK runs layer.new or layer.newSublayer with the fields. In isolation mode, a layer that would be outside the isolated art is an error and nothing opens", + "{sublayer?: bool} open Layer Options for a new layer (or a sublayer of the current layer), named and coloured as it would be: dialog `layerOptions` with mode new|newSublayer; OK runs layer.new or layer.newSublayer with the fields. In isolation mode, a layer that would be outside the isolated art is an error and nothing opens; OK checks again, and with isolation mode started since, it returns the same error and makes no layer", ), ( "ui.newArtboard", diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index adcb12b5a4..ac53a63c27 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -257,14 +257,14 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { ui.data_mut(|d| d.insert_temp(key("seen-current"), current)); } // Entering isolation mode opens the isolated row, now the top row, and scrolls to it; leaving it - // opens the rows around the row that was isolated and scrolls to that row. Showing another - // document changes neither. - let uid = app.session.active().map(|st| st.uid); - let isolated = app.session.active().and_then(|st| st.isolation).filter(|i| doc.node(*i).is_some()); - let seen_isolated: Option<(Option, Option)> = ui.data(|d| d.get_temp(key("seen-isolation"))); - if seen_isolated != Some((uid, isolated)) { - let was = seen_isolated.filter(|(u, _)| *u == uid).and_then(|(_, i)| i); - if seen_isolated.is_none_or(|(u, _)| u == uid) { + // opens the rows around the row that was isolated and scrolls to that row. Each document's + // isolation mode is followed on its own: a document first shown in isolation mode opens its + // isolated row, and showing again a document whose isolation mode did not change opens nothing. + if let Some(uid) = app.session.active().map(|st| st.uid) { + let isolated = app.session.active().and_then(|st| st.isolation).filter(|i| doc.node(*i).is_some()); + let mut seen: std::collections::HashMap> = ui.data(|d| d.get_temp(key("seen-isolation"))).unwrap_or_default(); + let was = seen.get(&uid).copied(); + if was != Some(isolated) { match isolated { Some(root) => { if let Some(st) = app.session.active_mut() { @@ -273,14 +273,15 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { reveal = Some(root); } None => { - if let Some(was) = was.filter(|i| doc.node(*i).is_some()) { + if let Some(was) = was.flatten().filter(|i| doc.node(*i).is_some()) { open_around(app, &doc, &[was]); reveal = Some(was); } } } + seen.insert(uid, isolated); + ui.data_mut(|d| d.insert_temp(key("seen-isolation"), seen)); } - ui.data_mut(|d| d.insert_temp(key("seen-isolation"), (uid, isolated))); } // With Locate Selected Objects on, an object selected anew outside the panel (below). let located = newly_selected(app, ui).filter(|_| !highlighted); diff --git a/crates/ui-egui/src/panels/layers/controls.rs b/crates/ui-egui/src/panels/layers/controls.rs index 89bd4288dc..c01594a329 100644 --- a/crates/ui-egui/src/panels/layers/controls.rs +++ b/crates/ui-egui/src/panels/layers/controls.rs @@ -126,7 +126,8 @@ pub(super) fn bottom_bar(app: &mut VectorcraftApp, ui: &mut Ui, view: &View, doc // With Show Layers Only on, Locate Object becomes Locate Layer: it highlights the layer row. let layers_only = view.opts.layers_only; let locate = if layers_only { tl!("Locate Layer") } else { tl!("Locate Object") }; - if widgets::icon_button(&mut child, "search", locate, false, 24.0).clicked() { + let locate_ok = !layers_only || super::rows::locate_layer_listed(doc, view.root); + if widgets::icon_button_enabled(&mut child, "search", locate, false, locate_ok, 24.0).clicked() { actions.push(("layer.locate".into(), json!({ "layersOnly": layers_only }))); } } @@ -165,7 +166,8 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { let mut items: Vec> = vec![ Some(("New Layer…", "ui.newLayer", json!({}), new_layer_ok, false)), Some(("New Sublayer…", "ui.newLayer", json!({"sublayer": true}), current.is_some() && new_sublayer_ok, false)), - Some(("Duplicate Selection", "layer.duplicate", json!({}), duplicate_ok, false)), + // The rows listed, so no highlighted row outside the isolated art is copied. + Some(("Duplicate Selection", "layer.duplicate", json!({"ids": targets.iter().map(|i| i.0).collect::>()}), duplicate_ok, false)), Some(("Delete Selection", "ui.layerDelete", json!({}), !targets.is_empty(), false)), Some(("Options for Selection…", "ui.layerOptions", json!({}), !targets.is_empty(), false)), None, @@ -181,7 +183,7 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { items.extend([ None, Some(if layers_only { - ("Locate Layer", "layer.locate", json!({"layersOnly": true}), has_sel, false) + ("Locate Layer", "layer.locate", json!({"layersOnly": true}), has_sel && super::rows::locate_layer_listed(&doc, st.isolation), false) } else { ("Locate Object", "layer.locate", json!({}), has_sel, false) }), @@ -199,28 +201,29 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { None, Some(("Template", "layer.template", json!({}), !layers_in.is_empty(), template)), ]); - // Each pair reads by state: Hide Others while another layer shows, else Show All Layers. + // Each pair reads by state: Hide Others while another layer shows, else Show All Layers. In + // isolation mode the other layers are outside the isolated art, so the pairs are off. let any_other = |f: &dyn Fn(&Node) -> bool| others.iter().any(|l| f(l)); items.push(Some(if any_other(&|l| l.visible) { - ("Hide Others", "layer.hideOthers", json!({}), true, false) + ("Hide Others", "layer.hideOthers", json!({}), !isolated, false) } else { - ("Show All Layers", "layer.showAll", json!({}), all_layers.iter().any(|l| !l.visible), false) + ("Show All Layers", "layer.showAll", json!({}), !isolated && all_layers.iter().any(|l| !l.visible), false) })); items.push(Some(if any_other(&|l| !matches!(l.kind, NodeKind::Layer { preview: false, .. })) { - ("Outline Others", "layer.outlineOthers", json!({}), true, false) + ("Outline Others", "layer.outlineOthers", json!({}), !isolated, false) } else { ( "Preview All Layers", "layer.previewAll", json!({}), - all_layers.iter().any(|l| matches!(l.kind, NodeKind::Layer { preview: false, .. })), + !isolated && all_layers.iter().any(|l| matches!(l.kind, NodeKind::Layer { preview: false, .. })), false, ) })); items.push(Some(if any_other(&|l| !l.locked) { - ("Lock Others", "layer.lockOthers", json!({}), true, false) + ("Lock Others", "layer.lockOthers", json!({}), !isolated, false) } else { - ("Unlock All Layers", "layer.unlockAll", json!({}), all_layers.iter().any(|l| l.locked), false) + ("Unlock All Layers", "layer.unlockAll", json!({}), !isolated && all_layers.iter().any(|l| l.locked), false) })); items.push(None); let remembers = doc.paste_remembers_layers; @@ -304,8 +307,8 @@ fn save_selection_menu(app: &mut VectorcraftApp, ui: &mut Ui) { /// `layer.delete` takes (default: the highlighted rows, else the current layer; in isolation mode a /// current layer outside the isolated art is an error). When a layer or sublayer among them holds art (an object other than a /// guide, hidden, locked and nested ones included), it asks first: OK deletes those rows, by id, in -/// the same document (`doc`, its uid, with `confirmed`); with another document active then, nothing -/// is deleted. Other rows, and rows `layer.delete` refuses (an unknown id, every top-level layer), +/// the same document (`doc`, its uid, with `confirmed`); with another document active then, or in +/// isolation mode with one of them outside the isolated art, nothing is deleted. Other rows, and rows `layer.delete` refuses (an unknown id, every top-level layer), /// go to `layer.delete` at once. → `layer.delete`'s result, or null while the question is open pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result { let confirmed = crate::menus::opt_bool(p, "confirmed")?.unwrap_or(false); @@ -332,6 +335,11 @@ pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result { Some(if rows.is_empty() { st.current_layer().into_iter().collect() } else { rows }) } }; + // Isolation mode can start while the question is open: OK then deletes nothing when a row it + // asked about is outside the isolated art. + if confirmed && ids.as_ref().is_some_and(|ids| ids.iter().any(|id| !in_isolated_art(st, *id))) { + return Err("the object is outside the isolated group".into()); + } let Some(ids) = ids.filter(|_| !confirmed) else { return app.run("layer.delete", Value::Object(rows)) }; let listed: HashSet = ids.iter().copied().collect(); let mut roots = vec![]; diff --git a/crates/ui-egui/src/panels/layers/model.rs b/crates/ui-egui/src/panels/layers/model.rs index 35a999a3c8..201d65fb1d 100644 --- a/crates/ui-egui/src/panels/layers/model.rs +++ b/crates/ui-egui/src/panels/layers/model.rs @@ -266,7 +266,8 @@ pub(super) fn isolated_root(doc: &Document, id: NodeId) -> Option<(&Arc, b /// Add the rows of `n` and those open inside it to `out`; `(colour, shown)` are those of what holds /// it (the layer's colour, and whether it is visible). The last item of `cx` is the document's -/// ruler guide ids by `guide.list` index. +/// ruler guide ids by `guide.list` index. With Show Layers Only on, a group or object at `depth` 0, +/// the isolated row in isolation mode, keeps its own row. pub(super) fn push_rows( n: &Arc, depth: usize, @@ -277,7 +278,7 @@ pub(super) fn push_rows( ) { let (open_rows, opts, query, filter, all_guides) = cx; // A ruler guide node gets no object row: its layer lists the guide rows. - if n.is_ruler_guide() || (opts.layers_only && !n.is_layer()) { + if n.is_ruler_guide() || (opts.layers_only && depth > 0 && !n.is_layer()) { return; } let colour = match &n.kind { diff --git a/crates/ui-egui/src/panels/layers/rows.rs b/crates/ui-egui/src/panels/layers/rows.rs index f1c1e1f6bc..57a92c824c 100644 --- a/crates/ui-egui/src/panels/layers/rows.rs +++ b/crates/ui-egui/src/panels/layers/rows.rs @@ -604,11 +604,13 @@ fn row_context_menu(ui: &mut Ui, view: &View, n: &Node, collect_ids: &[u64], out ui.close(); } ui.separator(); + // In isolation mode the other layers are outside the isolated art, so these pairs are off. + let isolated = view.root.is_some(); // Lock Others / Unlock All Layers { let (lock_cmd, lock_params, lock_enabled) = multi_others_action(view.doc, collect_ids, false); let lock_label = if lock_cmd == "layer.lockOthers" { "Lock Others" } else { "Unlock All Layers" }; - if widgets::menu_item(ui, lock_label, lock_enabled, false) { + if widgets::menu_item(ui, lock_label, lock_enabled && !isolated, false) { out.actions.push((lock_cmd, lock_params)); ui.close(); } @@ -617,7 +619,7 @@ fn row_context_menu(ui: &mut Ui, view: &View, n: &Node, collect_ids: &[u64], out { let (hide_cmd, hide_params, hide_enabled) = multi_others_action(view.doc, collect_ids, true); let hide_label = if hide_cmd == "layer.hideOthers" { "Hide Others" } else { "Show All Layers" }; - if widgets::menu_item(ui, hide_label, hide_enabled, false) { + if widgets::menu_item(ui, hide_label, hide_enabled && !isolated, false) { out.actions.push((hide_cmd, hide_params)); ui.close(); } @@ -625,7 +627,8 @@ fn row_context_menu(ui: &mut Ui, view: &View, n: &Node, collect_ids: &[u64], out ui.separator(); // Locate Object, or Locate Layer with Show Layers Only on let layers_only = view.opts.layers_only; - if widgets::menu_item(ui, if layers_only { "Locate Layer" } else { "Locate Object" }, true, false) { + let locate_ok = !layers_only || locate_layer_listed(view.doc, view.root); + if widgets::menu_item(ui, if layers_only { "Locate Layer" } else { "Locate Object" }, locate_ok, false) { out.actions.push(("layer.locate".into(), json!({ "id": n.id.0, "layersOnly": layers_only }))); ui.close(); } @@ -708,6 +711,13 @@ fn layer_row(n: &Node, own: Option) -> NodeId { if n.is_ruler_guide() { own.unwrap_or(n.id) } else { n.id } } +/// Whether Locate Layer can highlight a row the panel lists: outside isolation mode, or with a +/// layer or sublayer isolated (`root`). An isolated group or object holds no layer row, and the +/// layer holding it is not listed. +pub(super) fn locate_layer_listed(doc: &Document, root: Option) -> bool { + root.is_none_or(|r| doc.node(r).is_some_and(Node::is_layer)) +} + /// The eye and lock columns of row `n` at `r`. fn eye_and_lock(ui: &mut Ui, view: &View, n: &Node, r: egui::Rect, out: &mut Out) { let t = &view.t; @@ -738,11 +748,17 @@ fn eye_and_lock(ui: &mut Ui, view: &View, n: &Node, r: egui::Rect, out: &mut Out icons::paint(ui, "lock", egui::Rect::from_center_size(lock.center(), vec2(12.0, 12.0)), t.text_disabled); } let m = ui.input(|i| i.modifiers); + // In isolation mode the other layers are outside the isolated art: Alt-clicks change nothing. + let isolated = view.root.is_some(); if er.clicked() { if m.alt && m.command { - out.actions.push(outline_others_action(view.doc, n)); + if !isolated { + out.actions.push(outline_others_action(view.doc, n)); + } } else if m.alt { - out.actions.push(others_action(view.doc, n, true)); + if !isolated { + out.actions.push(others_action(view.doc, n, true)); + } } else if m.command && n.is_layer() { // Ctrl/Cmd-click: Preview ↔ Outline for this layer. out.actions.push(("layer.setProps".into(), json!({"ids": [n.id.0], "preview": !preview}))); @@ -751,7 +767,9 @@ fn eye_and_lock(ui: &mut Ui, view: &View, n: &Node, r: egui::Rect, out: &mut Out } } if lr.clicked() && m.alt { - out.actions.push(others_action(view.doc, n, false)); + if !isolated { + out.actions.push(others_action(view.doc, n, false)); + } } else if lr.clicked() { out.actions.push(("layer.setProps".into(), json!({"ids": [n.id.0], "locked": !n.locked}))); } @@ -781,8 +799,11 @@ fn drop_target(ui: &Ui, view: &View, n: &Node, r: egui::Rect, indent: f32, open: LayersDrag::Rows(ids) => ids.clone(), LayersDrag::Art => view.sel.iter().copied().collect(), LayersDrag::Guides(guides) => { - // Guides go to the layer of the row (the row's own, for a layer). - if let Some(layer) = if n.is_layer() { Some(n.id) } else { doc.layer_containing(n.id) } { + // Guides go to the layer of the row (the row's own, for a layer); in isolation mode only + // to a layer inside the isolated art. + if let Some(layer) = if n.is_layer() { Some(n.id) } else { doc.layer_containing(n.id) } + && view.root.is_none_or(|r| doc.ancestry(layer).is_some_and(|a| a.contains(&r))) + { guide_drop(ui, view, guides, layer, r, resp, out); } return; @@ -809,9 +830,9 @@ fn drop_target(ui: &Ui, view: &View, n: &Node, r: egui::Rect, indent: f32, open: LayersDrag::Rows(_) | LayersDrag::Guides(_) => Place::Below, }; // In isolation mode the isolated row takes a drop only inside it, so nothing leaves the isolated - // art or lands beside it. + // art or lands beside it; held over its own row, it goes nowhere. let place = if view.root == Some(n.id) { - if !inside { + if !inside || beside_itself { return; } Place::Inside diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index aef3fdf612..f24694091a 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -816,12 +816,15 @@ fn isolation_opens_the_isolated_row_and_keeps_drops_inside_it() { let (circles, _) = frame(&mut app, &ctx, vec![], false); assert_eq!(circles.len(), 4, "the sublayer's row opens"); // Rectangle a onto the upper edge of the sublayer's row: not above it, outside the sublayer. - drag(&mut app, &ctx, egui::pos2(150.0, circles[3].y), egui::pos2(150.0, circles[0].y - ROW_MEDIUM * 0.4), false); + let primary = egui::PointerButton::Primary; + let dragged = drag_by(&mut app, &ctx, egui::pos2(150.0, circles[3].y), egui::pos2(150.0, circles[0].y - ROW_MEDIUM * 0.4), false, primary); + assert!(dragged, "the drag started"); assert_eq!(parent(&app, a), Some(sub)); // The sublayer into the empty space under the rows: it stays in Layer 1. let (circles, _) = frame(&mut app, &ctx, vec![], false); assert_eq!(circles.len(), 4); - drag(&mut app, &ctx, egui::pos2(150.0, circles[0].y), egui::pos2(150.0, circles[3].y + 3.0 * ROW_MEDIUM), false); + let dragged = drag_by(&mut app, &ctx, egui::pos2(150.0, circles[0].y), egui::pos2(150.0, circles[3].y + 3.0 * ROW_MEDIUM), false, primary); + assert!(dragged, "the drag started"); assert_eq!(parent(&app, sub), Some(layer)); // Rectangle a onto the middle of the group's row: into it. let (circles, _) = frame(&mut app, &ctx, vec![], false); @@ -829,7 +832,7 @@ fn isolation_opens_the_isolated_row_and_keeps_drops_inside_it() { let (from, to) = (at(&app, a), at(&app, g)); drag(&mut app, &ctx, egui::pos2(150.0, from.y), egui::pos2(150.0, to.y), false); assert_eq!(parent(&app, a), Some(g)); - app.session.execute("object.exitIsolation", &json!({})).unwrap(); + app.session.execute("object.exitIsolation", &json!({"all": true})).unwrap(); let (circles, _) = frame(&mut app, &ctx, vec![], false); assert_eq!(circles.len(), 6, "every row again"); } @@ -916,10 +919,192 @@ fn isolation_keeps_new_layers_to_the_rows_listed() { assert!(!new_layer_unlisted(st, true, false), "a new sublayer goes inside it"); app.run("ui.newLayer", json!({"sublayer": true})).unwrap(); assert!(app.ui.dialog.is_some()); + // Exit Isolation Mode on the sublayer isolates its layer, beside which a new layer would go. + app.session.execute("object.exitIsolation", &json!({})).unwrap(); + assert!(new_layer_unlisted(app.session.active().unwrap(), false, true)); app.session.execute("object.exitIsolation", &json!({})).unwrap(); assert!(!new_layer_unlisted(app.session.active().unwrap(), false, true)); } +/// With Show Layers Only on, an isolated group or object is still listed as the top row, without +/// the art inside it, and its row can be renamed. +#[test] +fn isolation_with_show_layers_only_lists_the_isolated_group_or_object() { + let (mut app, [_, sub, g, _, a, _]) = nested(); + let opts = PanelOptions { layers_only: true, ..Default::default() }; + let listed = |app: &VectorcraftApp| { + let st = app.session.active().unwrap(); + list_rows(&st.doc, st.isolation, &st.layers_open, &opts, "", &Filter::default()).iter().map(|r| r.node.id).collect::>() + }; + app.session.execute("object.isolate", &json!({"id": g.0})).unwrap(); + assert_eq!(listed(&app), [g], "the group's row, without its art"); + let st = app.session.active().unwrap(); + assert!(listed_when_opened(&st.doc, st.isolation, &st.layers_open, &opts, "", &Filter::default(), g)); + app.session.execute("object.isolate", &json!({"id": a.0})).unwrap(); + assert_eq!(listed(&app), [a]); + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + assert_eq!(listed(&app), [sub], "a sublayer with no sublayers inside lists itself alone"); +} + +/// Click the item of the Layers panel menu whose text ends with `label`. +fn click_menu_item(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) { + let draw = |app: &mut VectorcraftApp, events: Vec| { + let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| menu(app, ui)); + out.textures_delta.clear(); + out.shapes.iter().find_map(|c| match &c.shape { + egui::Shape::Text(t) if t.galley.text().ends_with(label) => Some(t.visual_bounding_rect()), + _ => None, + }) + }; + let Some(r) = draw(app, vec![]) else { panic!("no menu item {label}") }; + for e in [egui::Event::PointerMoved(r.center()), button(r.center(), true), button(r.center(), false)] { + draw(app, vec![e]); + } +} + +/// In isolation mode the panel menu's Duplicate Selection copies only the rows the panel lists, Hide +/// Others is off, and with a group isolated so is Locate Layer, whose layer row is not listed. +#[test] +fn isolation_keeps_the_panel_menu_to_the_rows_listed() { + let (mut app, [layer, sub, g, b, _, c]) = nested(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let top = NodeId(app.session.execute("layer.new", &json!({"top": true, "name": "Top"})).unwrap()["id"].as_u64().unwrap()); + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + // A row left highlighted outside the sublayer before the panel shows again. + app.session.active_mut().unwrap().layer_rows = vec![c, b]; + click_menu_item(&mut app, &ctx, "Duplicate Selection"); + let count = |app: &VectorcraftApp, id: NodeId| app.session.active().unwrap().doc.node(id).unwrap().children().unwrap().len(); + assert_eq!(count(&app, layer), 2, "rectangle c, outside the sublayer, is not copied"); + assert_eq!(count(&app, g), 2, "rectangle b is copied"); + click_menu_item(&mut app, &ctx, "Hide Others"); + assert!(app.session.active().unwrap().doc.node(top).unwrap().visible, "the layer outside the isolated art still shows"); + app.ui.layers_panel.layers_only = true; + app.session.execute("object.isolate", &json!({"id": g.0})).unwrap(); + app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap(); + app.session.active_mut().unwrap().layer_rows = vec![]; + click_menu_item(&mut app, &ctx, "Locate Layer"); + assert!(rows_of(&app).is_empty(), "the sublayer holding the group is not highlighted"); +} + +/// OK in Delete Selection's question deletes nothing when isolation mode started while it asked and +/// a row it asked about is outside the isolated art. +#[test] +fn isolation_keeps_a_confirmed_delete_to_the_rows_listed() { + let (mut app, [_, sub, g, ..]) = nested(); + let uid = app.session.active().unwrap().uid; + app.session.active_mut().unwrap().layer_rows = vec![sub]; + assert!(app.run("ui.layerDelete", json!({})).unwrap().is_null(), "it asks first"); + app.session.execute("object.isolate", &json!({"id": g.0})).unwrap(); + let ok = json!({"ids": [sub.0], "doc": uid, "confirmed": true}); + let err = app.run("ui.layerDelete", ok.clone()).unwrap_err(); + assert!(err.contains("the object is outside the isolated group"), "{err}"); + assert!(app.session.active().unwrap().doc.node(sub).is_some(), "nothing was deleted"); + app.session.execute("object.exitIsolation", &json!({})).unwrap(); + app.run("ui.layerDelete", ok).unwrap(); + assert!(app.session.active().unwrap().doc.node(sub).is_none()); +} + +/// A document first shown in isolation mode opens its isolated row, also when the panel showed +/// another document last; shown again with its isolation mode unchanged, it opens nothing. +#[test] +fn isolation_opens_the_isolated_row_of_each_document() { + let (mut app, [_, _, g, ..]) = nested(); + let ctx = egui::Context::default(); + app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap(); + frame(&mut app, &ctx, vec![], false); + app.session.execute("document.activate", &json!({"index": 0})).unwrap(); + app.session.active_mut().unwrap().layers_open.set(g, false); + app.session.execute("object.isolate", &json!({"id": g.0})).unwrap(); + frame(&mut app, &ctx, vec![], false); + assert!(app.session.active().unwrap().layers_open.contains(g), "the isolated group's row opens"); + app.session.active_mut().unwrap().layers_open.set(g, false); + app.session.execute("document.activate", &json!({"index": 1})).unwrap(); + frame(&mut app, &ctx, vec![], false); + app.session.execute("document.activate", &json!({"index": 0})).unwrap(); + frame(&mut app, &ctx, vec![], false); + assert!(!app.session.active().unwrap().layers_open.contains(g), "a row closed in isolation mode stays closed"); +} + +/// In isolation mode an Alt-drag of the isolated row onto itself shows no place to drop and copies +/// nothing, and a guide dragged since before isolation mode began goes to no layer outside the +/// isolated art. +#[test] +fn isolation_keeps_drops_on_the_isolated_row_inside_it() { + let (mut app, [layer, sub, g, ..]) = nested(); + app.session.execute("guide.add", &json!({"vertical": true, "pos": 50, "layer": layer.0})).unwrap(); + let ctx = egui::Context::default(); + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + // Rows: Sub, g, b, a. + let (circles, _) = frame(&mut app, &ctx, vec![], false); + assert_eq!(circles.len(), 4); + let nodes = |app: &VectorcraftApp| { + let mut n = 0; + app.session.active().unwrap().doc.walk(|_| n += 1); + n + }; + let before = nodes(&app); + // The boxes drawn around a row that would take the drop, in one frame with Alt held. + let boxes = |app: &mut VectorcraftApp, e: egui::Event| { + let events = vec![egui::Event::ModifiersChanged(egui::Modifiers::ALT), e]; + let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| show(app, ui)); + out.textures_delta.clear(); + let accent = Tokens::get(&ctx).accent; + out.shapes.iter().filter(|c| matches!(&c.shape, egui::Shape::Rect(r) if r.stroke.width == 2.0 && r.stroke.color == accent)).count() + }; + let (from, to) = (egui::pos2(150.0, circles[0].y - 6.0), egui::pos2(150.0, circles[0].y + 2.0)); + boxes(&mut app, egui::Event::PointerMoved(from)); + boxes(&mut app, button(from, true)); + boxes(&mut app, egui::Event::PointerMoved(from + vec2(0.0, 6.0))); + let shown = boxes(&mut app, egui::Event::PointerMoved(to)) + boxes(&mut app, egui::Event::PointerMoved(to + vec2(1.0, 0.0))); + assert!(egui::DragAndDrop::has_any_payload(&ctx), "the drag started"); + assert_eq!(shown, 0, "no box around the isolated row"); + boxes(&mut app, button(to, false)); + frame(&mut app, &ctx, vec![], false); + assert_eq!(nodes(&app), before, "nothing was copied"); + app.session.execute("object.exitIsolation", &json!({"all": true})).unwrap(); + // Rows: Layer 1, its guide (no target circle), Sub, g, b, a, c. + let (circles, _) = frame(&mut app, &ctx, vec![], false); + assert_eq!(circles.len(), 6); + let guide_row = egui::pos2(150.0, (circles[0].y + circles[1].y) / 2.0); + click_with(&mut app, &ctx, guide_row, egui::Modifiers::NONE); + frame(&mut app, &ctx, vec![button(guide_row, true)], false); + frame(&mut app, &ctx, vec![egui::Event::PointerMoved(guide_row + vec2(0.0, 6.0))], false); + // Over the group's row the guide would go to the sublayer holding it. + let over = egui::pos2(150.0, circles[2].y); + let shown = boxes(&mut app, egui::Event::PointerMoved(over)) + boxes(&mut app, egui::Event::PointerMoved(over + vec2(1.0, 0.0))); + assert!(shown > 0, "a box around the group's row"); + app.session.execute("object.isolate", &json!({"id": g.0})).unwrap(); + // Rows: g, b. + let (circles, _) = frame(&mut app, &ctx, vec![], false); + let over = egui::pos2(150.0, circles[0].y); + let shown = boxes(&mut app, egui::Event::PointerMoved(over)) + boxes(&mut app, egui::Event::PointerMoved(over + vec2(1.0, 0.0))); + assert!(egui::DragAndDrop::has_any_payload(&ctx), "the guide is still dragged"); + assert_eq!(shown, 0, "no box around the isolated group's row, outside which its sublayer is"); + frame(&mut app, &ctx, vec![button(over, false)], false); + frame(&mut app, &ctx, vec![], false); + assert_eq!(app.session.active().unwrap().doc.ruler_guides()[0].layer, Some(layer), "the guide stays on Layer 1"); +} + +/// In isolation mode Alt-clicking or Ctrl/Cmd+Alt-clicking an eye, or Alt-clicking a lock, changes +/// no layer outside the isolated art. +#[test] +fn isolation_keeps_alt_clicks_on_eyes_and_locks_inside_it() { + let (mut app, [_, sub, ..]) = nested(); + let top = NodeId(app.session.execute("layer.new", &json!({"top": true, "name": "Top"})).unwrap()["id"].as_u64().unwrap()); + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + let ctx = egui::Context::default(); + let (circles, _) = frame(&mut app, &ctx, vec![], false); + let click = |app: &mut VectorcraftApp, at: egui::Pos2, mods: egui::Modifiers| click_with(app, &ctx, at, mods); + let (eye, lock) = (egui::pos2(12.0, circles[0].y), egui::pos2(37.0, circles[0].y)); + click(&mut app, eye, egui::Modifiers::ALT); + click(&mut app, eye, egui::Modifiers::ALT | egui::Modifiers::COMMAND); + click(&mut app, lock, egui::Modifiers::ALT); + let st = app.session.active().unwrap(); + let t = st.doc.node(top).unwrap(); + assert!(t.visible && !t.locked && !matches!(t.kind, NodeKind::Layer { preview: false, .. }), "the layer outside the isolated art is unchanged"); +} + // ---- rows at every depth (layers, sublayers, groups, objects) ---- /// Layer 1 holding rectangle `c` and a sublayer holding rectangle `a` and a group of diff --git a/docs/mcp.md b/docs/mcp.md index 175c225c58..1c0217dcaf 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5874,13 +5874,16 @@ and `layerRows`, the rows highlighted in the panel. locked or nested art included, dialog `confirm` asks "Delete this layer and its artwork?" for one layer, else "Delete the selected items and their artwork?"; OK deletes the rows it asked about in that document, one undo step, and Cancel keeps them; an empty layer, a layer with only guides, and groups or objects alone are deleted at once; in - isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted), + isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted, + and OK deletes nothing when isolation mode started while it asked and a row it asked about is outside the isolated + art), `layer.locate {id?, layersOnly?}` (highlights the selected object's row, or with several selected the row of the one frontmost in the stacking order, whatever order they were selected in; an `id` locates that object instead; the panel opens the rows around it; it scrolls to it on every call, also when the row was already highlighted; `layersOnly: true`, which the panel sends while Show Layers Only is on, as Locate Layer, highlights the innermost - layer or sublayer holding the object instead, or a layer `id` itself, and returns `{id, objectId, ancestry}`) + layer or sublayer holding the object instead, or a layer `id` itself, and returns `{id, objectId, ancestry}`; with a + group or object isolated, the panel's Locate Layer is off) and `layer.clippingMask.toggle`. - **Panel menu**: `layer.duplicate {ids?}`, `layer.merge {ids?}` (into the layer highlighted last, keeping the stacking order), `layer.flatten {id?}` (every other visible layer's art into one layer; hidden layers are deleted, @@ -5889,7 +5892,8 @@ and `layerRows`, the rows highlighted in the panel. `layer.reverse {ids?}`, `layer.template {ids?, on?}`, `layer.hideOthers` / `layer.showAll`, `layer.outlineOthers` / `layer.previewAll` (Ctrl/Cmd+Alt-clicking an eye runs Outline Others for the row's layer, or Preview All Layers when the others are in Outline already), `layer.lockOthers` / `layer.unlockAll` (Alt-clicking an eye or a lock - runs Hide or Lock Others for the row's layer, or Show or Unlock All when the others already are), `layer.pasteRemembersLayers`, + runs Hide or Lock Others for the row's layer, or Show or Unlock All when the others already are; in isolation mode + the panel's menu and row menu turn these pairs off, and the Alt-clicks change nothing), `layer.pasteRemembersLayers`, `object.isolate {id?}` (a group, a layer or a single object, by default the first selected object; not type, not a hidden or locked object or one in a hidden or locked group or layer, not a guide path while Lock Guides is on, and while a symbol is edited only the editing layer or art on it) / `object.exitIsolation {all?}`. With a sublayer @@ -5914,8 +5918,8 @@ and `layerRows`, the rows highlighted in the panel. dimImages, dimPercent; OK is one undo step; `ui.dialog.set` of `template` also sets `locked` and `dimImages`, as the checkbox does, except a Dim Images set before it; for several `ids` the dialog shows the first row's settings, and OK sends only the fields set with a control or `ui.dialog.set`; Cmd/Ctrl+Alt+L runs `ui.newLayer` for a new layer; in isolation mode `ui.newLayer` for a - layer that would be outside the isolated art is an error, and the Layers panel's New Layer and New Sublayer are off - then), `ui.layersPanelOptions` opens Panel Options (`layersPanelOptions`: + layer that would be outside the isolated art is an error, OK in the dialog checks again and returns the same error, + and the Layers panel's New Layer and New Sublayer are off then), `ui.layersPanelOptions` opens Panel Options (`layersPanelOptions`: layersOnly, locateSelected, rowSize small|medium|large|other, otherSize, thumbLayers, thumbGroups, thumbObjects), and `ui.layersExpand {ids?, open?}` opens or closes rows as their triangles do (Alt-click: everything inside). With `locateSelected` on (Locate Selected Objects, off by default), when the last selected object changes on the canvas From 8e98dbb310ad8aae793999393a42790fdb492c89 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 17:36:46 -0800 Subject: [PATCH 3/4] Isolation: object.isolate refuses a ruler guide An isolated ruler guide left the Layers panel with no rows, since the panel lists no object row for a ruler guide. object.isolate now returns "ruler guides can't be isolated" and isolation mode stays as it was. --- crates/engine/src/cmd/object/arrange.rs | 3 +++ crates/engine/src/cmd/object/commands.rs | 2 +- crates/engine/src/tests/menucmds.rs | 11 +++++++++++ docs/mcp.md | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/object/arrange.rs b/crates/engine/src/cmd/object/arrange.rs index 4250f3c377..a0f292fecf 100644 --- a/crates/engine/src/cmd/object/arrange.rs +++ b/crates/engine/src/cmd/object/arrange.rs @@ -334,6 +334,9 @@ pub(super) fn isolate(s: &mut Session, p: &Value) -> Result { if matches!(st.doc.node(id).ok_or(EngineError::NoNode(id))?.kind, NodeKind::Text(_)) { return Err(bad("object.isolate", "type objects can't be isolated")); } + if st.doc.node(id).is_some_and(|n| n.is_ruler_guide()) { + return Err(bad("object.isolate", "ruler guides can't be isolated")); + } let isolation = st.doc.node(id).filter(|n| n.extras().shaper.is_some()).and_then(|n| n.children()).and_then(|c| c.first()).map_or(id, |n| n.id); // A hidden or locked object, one in a hidden or locked group or layer, and a guide path while diff --git a/crates/engine/src/cmd/object/commands.rs b/crates/engine/src/cmd/object/commands.rs index 92f4744fea..0172a7466c 100644 --- a/crates/engine/src/cmd/object/commands.rs +++ b/crates/engine/src/cmd/object/commands.rs @@ -241,7 +241,7 @@ pub fn specs() -> Vec { "Enter Isolation Mode", [], None, - "{id?} isolate a group, a layer or a single object (default: the first selected object); type, a hidden or locked object, an object in a hidden or locked group or layer, and a guide path while Lock Guides is on are refused, and so is every object while an opacity mask is edited", + "{id?} isolate a group, a layer or a single object (default: the first selected object); type, a ruler guide, a hidden or locked object, an object in a hidden or locked group or layer, and a guide path while Lock Guides is on are refused, and so is every object while an opacity mask is edited", crate::cmd::maskedit::outside_mask_editing, isolate ), diff --git a/crates/engine/src/tests/menucmds.rs b/crates/engine/src/tests/menucmds.rs index 32ea203053..ef14bbaef9 100644 --- a/crates/engine/src/tests/menucmds.rs +++ b/crates/engine/src/tests/menucmds.rs @@ -4652,6 +4652,17 @@ fn exit_isolation_leaves_a_locked_guide_path_deselected() { assert_eq!(selected(&s), vec![g]); } +/// A ruler guide is not isolated, and isolation mode stays as it was. +#[test] +fn ruler_guides_are_not_isolated() { + let mut s = session(); + s.execute("guide.add", &json!({"vertical": true, "pos": 50})).unwrap(); + let guide = s.doc().unwrap().doc.ruler_guides()[0].id.unwrap(); + let err = s.execute("object.isolate", &json!({"id": guide.0})).unwrap_err(); + assert!(err.to_string().contains("ruler guides can't be isolated"), "{err}"); + assert_eq!(s.doc().unwrap().isolation, None); +} + /// Exit Isolation Mode on an isolated sublayer isolates its parent layer and selects the sublayer, one /// layer per call, without an undo step; from the top-level layer it leaves isolation mode. `all: true` /// leaves from any depth, a hidden parent layer is not isolated (the call leaves), and a group in a diff --git a/docs/mcp.md b/docs/mcp.md index 1c0217dcaf..1c50f93f9f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5895,7 +5895,7 @@ and `layerRows`, the rows highlighted in the panel. runs Hide or Lock Others for the row's layer, or Show or Unlock All when the others already are; in isolation mode the panel's menu and row menu turn these pairs off, and the Alt-clicks change nothing), `layer.pasteRemembersLayers`, `object.isolate {id?}` (a group, a layer or a single object, by default the first selected object; not type, not a - hidden or locked object or one in a hidden or locked group or layer, not a guide path while Lock Guides is on, and + ruler guide, not a hidden or locked object or one in a hidden or locked group or layer, not a guide path while Lock Guides is on, and while a symbol is edited only the editing layer or art on it) / `object.exitIsolation {all?}`. With a sublayer isolated, `object.exitIsolation` isolates its parent layer and selects the sublayer, so repeated calls go up one layer at a time until the top-level layer is left, as the From 686fd46c9ddafc311bced36a44aaa237a8bfd017 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 17:55:48 -0800 Subject: [PATCH 4/4] Layers: in isolation mode the trash deletes no row outside the isolated art Rows dragged to the trash before isolation mode started went to layer.delete at once when none needed a question. ui.layerDelete now returns an error for any row outside the isolated art, given or dropped, and deletes nothing. OK in its question with no rows given deletes the highlighted rows the panel lists, not every highlighted row. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panels/layers/controls.rs | 17 +++++++++++------ crates/ui-egui/src/panels/layers/tests.rs | 16 +++++++++++++--- docs/mcp.md | 4 ++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index a03e9e8538..7e894b5d5a 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1160,7 +1160,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.layerDelete", "Delete Selection", "", - "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, or in isolation mode with one of the rows outside the isolated art, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", + "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. In isolation mode a row outside the isolated art is an error and nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", ), ( "ui.rename", diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 6d950c882b..9d793c2966 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1161,7 +1161,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.layerDelete", "Delete Selection", "", - "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, or in isolation mode with one of the rows outside the isolated art, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", + "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. In isolation mode a row outside the isolated art is an error and nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", ), ( "ui.rename", diff --git a/crates/ui-egui/src/panels/layers/controls.rs b/crates/ui-egui/src/panels/layers/controls.rs index c01594a329..31f07c4929 100644 --- a/crates/ui-egui/src/panels/layers/controls.rs +++ b/crates/ui-egui/src/panels/layers/controls.rs @@ -307,8 +307,8 @@ fn save_selection_menu(app: &mut VectorcraftApp, ui: &mut Ui) { /// `layer.delete` takes (default: the highlighted rows, else the current layer; in isolation mode a /// current layer outside the isolated art is an error). When a layer or sublayer among them holds art (an object other than a /// guide, hidden, locked and nested ones included), it asks first: OK deletes those rows, by id, in -/// the same document (`doc`, its uid, with `confirmed`); with another document active then, or in -/// isolation mode with one of them outside the isolated art, nothing is deleted. Other rows, and rows `layer.delete` refuses (an unknown id, every top-level layer), +/// the same document (`doc`, its uid, with `confirmed`); with another document active then, nothing +/// is deleted. In isolation mode a row outside the isolated art is an error, and nothing is deleted. Other rows, and rows `layer.delete` refuses (an unknown id, every top-level layer), /// go to `layer.delete` at once. → `layer.delete`'s result, or null while the question is open pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result { let confirmed = crate::menus::opt_bool(p, "confirmed")?.unwrap_or(false); @@ -335,12 +335,17 @@ pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result { Some(if rows.is_empty() { st.current_layer().into_iter().collect() } else { rows }) } }; - // Isolation mode can start while the question is open: OK then deletes nothing when a row it - // asked about is outside the isolated art. - if confirmed && ids.as_ref().is_some_and(|ids| ids.iter().any(|id| !in_isolated_art(st, *id))) { + // Isolation mode can start while rows are dragged to the trash or while the question is open: + // nothing is deleted when a row is outside the isolated art. + if ids.as_ref().is_some_and(|ids| ids.iter().any(|id| !in_isolated_art(st, *id))) { return Err("the object is outside the isolated group".into()); } - let Some(ids) = ids.filter(|_| !confirmed) else { return app.run("layer.delete", Value::Object(rows)) }; + let ids = match ids { + // Confirmed without rows given: the rows the panel lists, not every highlighted row. + Some(ids) if confirmed && rows.is_empty() => return app.run("layer.delete", json!({ "ids": ids.iter().map(|i| i.0).collect::>() })), + Some(ids) if !confirmed => ids, + _ => return app.run("layer.delete", Value::Object(rows)), + }; let listed: HashSet = ids.iter().copied().collect(); let mut roots = vec![]; row_roots(&st.doc.layers, &listed, &mut roots); diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index f24694091a..403515b228 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -988,10 +988,11 @@ fn isolation_keeps_the_panel_menu_to_the_rows_listed() { } /// OK in Delete Selection's question deletes nothing when isolation mode started while it asked and -/// a row it asked about is outside the isolated art. +/// a row it asked about is outside the isolated art, and rows given outside it, as rows dropped on +/// the trash are, are not deleted either. #[test] fn isolation_keeps_a_confirmed_delete_to_the_rows_listed() { - let (mut app, [_, sub, g, ..]) = nested(); + let (mut app, [_, sub, g, _, a, c]) = nested(); let uid = app.session.active().unwrap().uid; app.session.active_mut().unwrap().layer_rows = vec![sub]; assert!(app.run("ui.layerDelete", json!({})).unwrap().is_null(), "it asks first"); @@ -1000,7 +1001,16 @@ fn isolation_keeps_a_confirmed_delete_to_the_rows_listed() { let err = app.run("ui.layerDelete", ok.clone()).unwrap_err(); assert!(err.contains("the object is outside the isolated group"), "{err}"); assert!(app.session.active().unwrap().doc.node(sub).is_some(), "nothing was deleted"); - app.session.execute("object.exitIsolation", &json!({})).unwrap(); + let err = app.run("ui.layerDelete", json!({"ids": [c.0]})).unwrap_err(); + assert!(err.contains("the object is outside the isolated group"), "{err}"); + assert!(app.session.active().unwrap().doc.node(c).is_some(), "the rectangle outside the group stays"); + // OK with no rows given deletes the highlighted rows the panel lists, inside the sublayer. + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + app.session.active_mut().unwrap().layer_rows = vec![a, c]; + app.run("ui.layerDelete", json!({"doc": uid, "confirmed": true})).unwrap(); + let doc = &app.session.active().unwrap().doc; + assert!(doc.node(a).is_none() && doc.node(c).is_some(), "only the row inside the sublayer is deleted"); + app.session.execute("object.exitIsolation", &json!({"all": true})).unwrap(); app.run("ui.layerDelete", ok).unwrap(); assert!(app.session.active().unwrap().doc.node(sub).is_none()); } diff --git a/docs/mcp.md b/docs/mcp.md index 1c50f93f9f..1640f8d67b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5875,8 +5875,8 @@ and `layerRows`, the rows highlighted in the panel. the selected items and their artwork?"; OK deletes the rows it asked about in that document, one undo step, and Cancel keeps them; an empty layer, a layer with only guides, and groups or objects alone are deleted at once; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted, - and OK deletes nothing when isolation mode started while it asked and a row it asked about is outside the isolated - art), + and so is a row outside it, given as `ids` or `id`, dropped on the trash or asked about before isolation mode + started), `layer.locate {id?, layersOnly?}` (highlights the selected object's row, or with several selected the row of the one frontmost in the stacking order, whatever order they were selected in; an `id` locates that object instead; the panel opens the rows around it;