mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 04:33:43 +00:00
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.
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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.
|
||||
@@ -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<u64>, Option<NodeId>)> = 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::<LayersDrag>(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<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")?;
|
||||
@@ -473,7 +513,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");
|
||||
@@ -487,10 +530,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);
|
||||
@@ -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<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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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})),
|
||||
@@ -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<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,
|
||||
@@ -149,9 +159,9 @@ 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)),
|
||||
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<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 })
|
||||
}
|
||||
};
|
||||
@@ -327,6 +341,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>) {
|
||||
|
||||
@@ -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,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<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.
|
||||
@@ -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<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 +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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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<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.
|
||||
@@ -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<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]);
|
||||
}
|
||||
|
||||
+5
-2
@@ -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
|
||||
|
||||
@@ -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`).
|
||||
|
||||
Reference in New Issue
Block a user