Merge pull request #8497 from dotCooCoo/feat/layers-panel-isolation-list

Layers: isolation mode lists only the isolated art
This commit is contained in:
BFlat
2026-11-19 15:00:00 +07:00
committed by GitHub
13 changed files with 680 additions and 81 deletions
+3
View File
@@ -334,6 +334,9 @@ pub(super) fn isolate(s: &mut Session, p: &Value) -> Result<Value> {
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
+1 -1
View File
@@ -241,7 +241,7 @@ pub fn specs() -> Vec<CommandSpec> {
"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
),
+11
View File
@@ -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
+3 -3
View File
@@ -1184,19 +1184,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, 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",
"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; OK checks again, and with isolation mode started since, it returns the same error and makes no layer",
),
(
"ui.newArtboard",
+34 -2
View File
@@ -157,9 +157,14 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
}
/// `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<Value, String> {
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<Value, String> {
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<Value, String> {
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();
+3 -3
View File
@@ -1185,19 +1185,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, 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",
"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; OK checks again, and with isolation mode started since, it returns the same error and makes no layer",
),
(
"ui.newArtboard",
+94 -23
View File
@@ -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<ColumnDrag>,
/// The row to scroll into view.
reveal: Option<NodeId>,
/// In isolation mode, the isolated node: the top row, which nothing is dropped beside.
root: Option<NodeId>,
/// 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.
@@ -237,16 +251,38 @@ 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. 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<u64, Option<NodeId>> = 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() {
st.layers_open.set(root, true);
}
reveal = Some(root);
}
None => {
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));
}
}
// 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.
@@ -265,7 +301,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]);
@@ -289,6 +327,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();
@@ -338,12 +377,14 @@ 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). The bottom layer itself goes there only as an Alt copy,
// which lands below it; moved, it would stay where it is (#8237).
// no row there to take the drop), except in isolation mode, where that layer is not listed.
// The bottom layer itself goes there only as an Alt copy, which lands below it; moved, it
// would stay where it is (#8237).
let below = list_rect.top() - scrolled.inner.state.clamped_offset().y + list.len() as f32 * view.h;
let alt = ui.input(|i| i.modifiers.alt);
if query.is_empty()
&& !app.ui.layers_filter.is_on()
&& view.root.is_none()
&& let Some(drag) = egui::DragAndDrop::payload::<LayersDrag>(ui.ctx())
&& let LayersDrag::Rows(ids) = &*drag
&& let Some(bottom) = doc.layers.first()
@@ -454,8 +495,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<Value, String> {
let ctx = app.ui_ctx.clone().ok_or("the Layers panel is not shown")?;
let st = app.session.active().ok_or("no document open")?;
@@ -483,7 +525,10 @@ pub fn rename(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
};
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");
@@ -497,10 +542,19 @@ pub fn rename(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
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<NodeId> =
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<NodeId> = 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::<Vec<_>>()).unwrap_or_default()
})
.collect();
if let Some(st) = app.session.active_mut() {
for a in around {
st.layers_open.set(a, true);
@@ -509,20 +563,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<NodeId>,
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)
}
+81 -22
View File
@@ -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::<LayersDrag>() {
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::<Vec<_>>()}))),
LayersDrag::Guides(guides) if deletes => actions.push(("guide.remove".into(), json!({"indexes": guides}))),
_ => {}
}
}
let over = button.dnd_hover_payload::<LayersDrag>().is_some_and(|d| match *d {
LayersDrag::Rows(_) => true,
let over = button.dnd_hover_payload::<LayersDrag>().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::<PanelDrag>().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})),
@@ -119,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 })));
}
}
@@ -131,12 +139,15 @@ 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 layers_only = app.ui.layers_panel.layers_only;
let targets: Vec<NodeId> = if rows.is_empty() { current.into_iter().collect() } else { rows.clone() };
let targets: Vec<NodeId> = 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,
@@ -153,9 +164,10 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
}
});
let mut items: Vec<Option<MenuItem>> = 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)),
// 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::<Vec<_>>()}), 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,
@@ -171,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)
}),
@@ -189,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;
@@ -291,10 +304,11 @@ 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),
/// 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<Value, String> {
let confirmed = crate::menus::opt_bool(p, "confirmed")?.unwrap_or(false);
@@ -314,11 +328,24 @@ pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
(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 })
}
};
let Some(ids) = ids.filter(|_| !confirmed) else { return app.run("layer.delete", Value::Object(rows)) };
// 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 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::<Vec<_>>() })),
Some(ids) if !confirmed => ids,
_ => return app.run("layer.delete", Value::Object(rows)),
};
let listed: HashSet<NodeId> = ids.iter().copied().collect();
let mut roots = vec![];
row_roots(&st.doc.layers, &listed, &mut roots);
@@ -335,6 +362,38 @@ pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
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<NodeId> {
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<NodeId> {
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<Node>], listed: &HashSet<NodeId>, out: &mut Vec<&'a Node>) {
+36 -7
View File
@@ -217,6 +217,7 @@ pub(super) fn parse_names<T: Copy + PartialEq>(p: &Value, key: &str, all: &[(T,
struct RowsKey {
uid: u64,
revision: u64,
isolation: Option<NodeId>,
open: u64,
layers_only: bool,
query: String,
@@ -224,22 +225,49 @@ 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<Row> {
/// 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<NodeId>, open: &OpenRows, opts: &PanelOptions, query: &str, filter: &Filter) -> Vec<Row> {
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<NodeId> = 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<Node>, 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.
/// 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<Node>,
depth: usize,
@@ -250,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 {
@@ -325,11 +353,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<Vec<Row>> {
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 +370,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
}
+42 -9
View File
@@ -587,7 +587,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();
}
@@ -602,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();
}
@@ -615,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();
}
@@ -623,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();
}
@@ -706,6 +711,13 @@ fn layer_row(n: &Node, own: Option<NodeId>) -> 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<NodeId>) -> 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;
@@ -736,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})));
@@ -749,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})));
}
@@ -779,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;
@@ -806,6 +829,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; held over its own row, it goes nowhere.
let place = if view.root == Some(n.id) {
if !inside || beside_itself {
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))
+359 -6
View File
@@ -763,6 +763,358 @@ 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.
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);
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);
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!({"all": true})).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(&current), "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());
// 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::<Vec<_>>()
};
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<egui::Event>| {
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, 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, _, 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");
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");
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());
}
/// 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
@@ -901,7 +1253,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 +1648,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),
@@ -2750,10 +3103,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();
@@ -2784,7 +3137,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<NodeId> = 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.
@@ -2810,7 +3163,7 @@ fn guide_rows_list_by_index_whatever_the_node_order() {
doc.move_node(first, Some(layer), usize::MAX).unwrap();
let kids: Vec<NodeId> = 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<usize> = rows.iter().filter_map(|r| r.guide).collect();
assert_eq!(indexes, [2, 1, 0]);
}
+12 -5
View File
@@ -6036,13 +6036,17 @@ 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,
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;
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,
@@ -6051,9 +6055,10 @@ 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
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
@@ -6075,7 +6080,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, 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
+1
View File
@@ -1248,6 +1248,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`).
- With a sublayer isolated, Exit Isolation Mode (the Layers panel menu item, the isolation bar's back arrow, the Control bar button and `object.exitIsolation`) goes back one layer at a time, isolating the parent layer, and leaves isolation mode from the top-level layer, as the [help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/select-objects/isolate-objects.html) and an archived [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=213) describe. As VectorCraft's own rules, Esc and the top-level layer's crumb leave isolation mode from a sublayer at any depth (`object.exitIsolation {all: true}`), a sublayer's crumb isolates that sublayer, a hidden or locked parent layer is not isolated, and a step up records no undo step (`exit_isolation_goes_up_one_layer_from_a_sublayer`, `isolation_bar_back_button_steps_up_through_sublayers`, `escape_leaves_an_isolated_sublayer_in_one_step`).
- 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).