mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 11:14:13 +00:00
Layers: a repeated Locate reveals the row it already highlighted
Running Locate Object or Locate Layer again on the row it already highlighted wrote the same highlight, so the Layers panel did not open the layers around the row or scroll to it: a sublayer whose layer was closed since stayed hidden. layer.locate now leaves a one-time request on the document (DocState::locate_reveal) that the panel takes on its next frame, opening the layers around the located row and scrolling to it whether or not the highlight changed. The request is not saved and adds no undo step, and the panel drops it when the row is no longer highlighted.
This commit is contained in:
@@ -132,7 +132,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Locate Object",
|
||||
["Window", "Layers"],
|
||||
None,
|
||||
"{id?, layersOnly?} (default: the last selected object) highlight the object's row; the Layers panel opens the layers around it and scrolls to it → {id, ancestry: [layer…, id]}. layersOnly (default false; the panel sends true while Show Layers Only is on, as Locate Layer) highlights the innermost layer or sublayer holding the object instead, or a layer id itself → {id: layer, objectId, ancestry: [layer…]}",
|
||||
"{id?, layersOnly?} (default: the last selected object) highlight the object's row; the Layers panel opens the layers around it and scrolls to it, also when the row was already highlighted →{id, ancestry: [layer…, id]}. layersOnly (default false; the panel sends true while Show Layers Only is on, as Locate Layer) highlights the innermost layer or sublayer holding the object instead, or a layer id itself → {id: layer, objectId, ancestry: [layer…]}",
|
||||
has_doc,
|
||||
locate
|
||||
),
|
||||
@@ -446,6 +446,7 @@ fn locate(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
let row = ancestry.last().copied().ok_or(EngineError::NoNode(id))?;
|
||||
st.layer_rows = vec![row];
|
||||
st.locate_reveal = Some(row);
|
||||
st.revision += 1;
|
||||
let ancestry: Vec<u64> = ancestry.iter().map(|i| i.0).collect();
|
||||
Ok(if layers_only { json!({ "id": row.0, "objectId": id.0, "ancestry": ancestry }) } else { json!({ "id": id.0, "ancestry": ancestry }) })
|
||||
|
||||
@@ -25,6 +25,10 @@ pub struct DocState {
|
||||
/// Panel state, not art selection: not saved, not undoable (`layer.setCurrent`,
|
||||
/// `layer.highlight`).
|
||||
pub layer_rows: Vec<NodeId>,
|
||||
/// The row the last Locate Object or Locate Layer (`layer.locate`) highlighted, until the
|
||||
/// Layers panel takes it: the panel opens the layers around that row and scrolls to it, also
|
||||
/// when the row was already highlighted. Panel state: not saved, not undoable.
|
||||
pub locate_reveal: Option<NodeId>,
|
||||
/// The variable highlighted in the Variables panel: what its Delete, Options… and Select
|
||||
/// Bound Object act on. Panel state, not art selection: not saved, not undoable
|
||||
/// (`variable.highlight`). A name, so renaming a variable moves the highlight with it.
|
||||
@@ -318,6 +322,7 @@ impl DocState {
|
||||
revision: 1,
|
||||
active_layer,
|
||||
layer_rows: vec![],
|
||||
locate_reveal: None,
|
||||
variables_highlight: None,
|
||||
variables_sort: Default::default(),
|
||||
isolation: None,
|
||||
|
||||
@@ -914,6 +914,12 @@ fn locate_layer_highlights_the_layer_holding_the_object() {
|
||||
let r = run(&mut s, "layer.locate", json!({"layersOnly": true}));
|
||||
assert_eq!(r, json!({"id": sub.0, "objectId": b.0, "ancestry": [layer.0, sub.0]}), "the group's sublayer");
|
||||
assert_eq!(s.doc().unwrap().highlighted_rows(), vec![sub]);
|
||||
assert_eq!(s.doc().unwrap().locate_reveal, Some(sub), "the Layers panel reveals the located row");
|
||||
s.doc_mut().unwrap().locate_reveal = None;
|
||||
let undo = s.doc().unwrap().history.undo.len();
|
||||
run(&mut s, "layer.locate", json!({"layersOnly": true}));
|
||||
assert_eq!(s.doc().unwrap().locate_reveal, Some(sub), "again for a row already highlighted");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo, "no undo step");
|
||||
assert_eq!(run(&mut s, "layer.locate", json!({"id": c.0, "layersOnly": true}))["id"], layer.0, "art directly in a layer");
|
||||
assert_eq!(s.doc().unwrap().highlighted_rows(), vec![layer]);
|
||||
let r = run(&mut s, "layer.locate", json!({"id": sub.0, "layersOnly": true}));
|
||||
@@ -924,6 +930,7 @@ fn locate_layer_highlights_the_layer_holding_the_object() {
|
||||
for p in [json!({"id": b.0, "layersOnly": "yes"}), json!({"id": 999_999, "layersOnly": true})] {
|
||||
assert!(s.execute("layer.locate", &p).is_err(), "{p}");
|
||||
assert_eq!(s.doc().unwrap().highlighted_rows(), vec![g], "{p}");
|
||||
assert_eq!(s.doc().unwrap().locate_reveal, Some(g), "{p}");
|
||||
}
|
||||
run(&mut s, "select.none", json!({}));
|
||||
assert!(s.execute("layer.locate", &json!({"layersOnly": true})).is_err(), "nothing selected");
|
||||
|
||||
@@ -221,6 +221,14 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
reveal = rows.first().copied();
|
||||
ui.data_mut(|d| d.insert_temp(key("seen"), rows.clone()));
|
||||
}
|
||||
// Locate Object or Locate Layer (`layer.locate`): the located row is revealed each time, also
|
||||
// when it was already highlighted and a layer around it was closed since or the list scrolled
|
||||
// away. A request for a row no longer highlighted is dropped.
|
||||
let locate = app.session.active_mut().and_then(|st| st.locate_reveal.take()).filter(|id| rows.contains(id));
|
||||
if let Some(id) = locate {
|
||||
open_around(app, &doc, &[id]);
|
||||
reveal = Some(id);
|
||||
}
|
||||
let highlighted = reveal.is_some();
|
||||
// A new active layer (a canvas selection highlights no row): reveal it too, unless a row
|
||||
// highlighted in the panel holds the view.
|
||||
|
||||
@@ -2177,6 +2177,53 @@ fn with_show_layers_only_locate_object_becomes_locate_layer() {
|
||||
assert!(has(&row_menu, "Locate Layer") && !has(&row_menu, "Locate Object"), "{row_menu:?}");
|
||||
}
|
||||
|
||||
/// Locate Layer or Locate Object run again on the row it already highlighted reveals that row
|
||||
/// again: the layers around it that were closed since open, once per Locate.
|
||||
#[test]
|
||||
fn a_repeated_locate_reveals_the_row_it_already_highlighted() {
|
||||
let (mut app, [layer, sub, g, b, _, _]) = nested();
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let draw = |app: &mut VectorcraftApp| {
|
||||
super::super::tests_appearance::frame_events(&ctx, app, vec![], show).into_iter().map(|(t, _)| t.trim().to_string()).collect::<Vec<_>>()
|
||||
};
|
||||
let open = |app: &VectorcraftApp, id: NodeId| app.session.active().unwrap().layers_open.contains(id);
|
||||
let close = |app: &mut VectorcraftApp, ids: &[NodeId]| {
|
||||
for id in ids {
|
||||
app.session.active_mut().unwrap().layers_open.set(*id, false);
|
||||
}
|
||||
};
|
||||
app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
|
||||
// Locate Layer: the sublayer stays highlighted while its layer is closed, and Locate Layer again opens it.
|
||||
app.ui.layers_panel.layers_only = true;
|
||||
app.session.execute("layer.locate", &json!({"layersOnly": true})).unwrap();
|
||||
draw(&mut app);
|
||||
assert_eq!(rows_of(&app), vec![sub]);
|
||||
close(&mut app, &[layer]);
|
||||
assert!(!draw(&mut app).iter().any(|t| t == "Sub"), "the closed layer hides the sublayer");
|
||||
app.session.execute("layer.locate", &json!({"layersOnly": true})).unwrap();
|
||||
assert!(draw(&mut app).iter().any(|t| t == "Sub"), "the sublayer's row shows again");
|
||||
assert!(open(&app, layer), "the layer around the sublayer opens again");
|
||||
assert_eq!(rows_of(&app), vec![sub]);
|
||||
// Once per Locate: a later frame leaves a layer closed after that alone.
|
||||
close(&mut app, &[layer]);
|
||||
draw(&mut app);
|
||||
assert!(!open(&app, layer), "a frame without a Locate opens nothing");
|
||||
|
||||
// Locate Object: the same for the object's row inside a closed sublayer and group.
|
||||
app.ui.layers_panel.layers_only = false;
|
||||
app.session.execute("layer.locate", &json!({})).unwrap();
|
||||
draw(&mut app);
|
||||
assert_eq!(rows_of(&app), vec![b]);
|
||||
close(&mut app, &[sub, g]);
|
||||
draw(&mut app);
|
||||
app.session.execute("layer.locate", &json!({})).unwrap();
|
||||
draw(&mut app);
|
||||
assert!(open(&app, layer) && open(&app, sub) && open(&app, g), "the layers and group around the object open again");
|
||||
assert_eq!(rows_of(&app), vec![b]);
|
||||
}
|
||||
|
||||
/// ≡ › Save Selection lists the saved selections: choosing one recalls it, Update Selection
|
||||
/// makes it hold the selected objects, and Save Selection… opens the name dialog.
|
||||
#[test]
|
||||
|
||||
+2
-2
@@ -5429,8 +5429,8 @@ and `layerRows`, the rows highlighted in the panel.
|
||||
locked or nested art included, dialog `confirm` asks "Delete this layer and its artwork?" for one layer, else "Delete
|
||||
the selected items and their artwork?"; OK deletes the rows it asked about in that document, one undo step, and
|
||||
Cancel keeps them; an empty layer, a layer with only guides, and groups or objects alone are deleted at once),
|
||||
`layer.locate {id?, layersOnly?}` (highlights the selected object's row; the panel opens the rows around it;
|
||||
`layersOnly: true`, which the panel sends while Show Layers Only is on, as Locate Layer, highlights the innermost
|
||||
`layer.locate {id?, layersOnly?}` (highlights the selected object's row; the panel opens the rows around it and
|
||||
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}`)
|
||||
and `layer.clippingMask.toggle`.
|
||||
- **Panel menu**: `layer.duplicate {ids?}`, `layer.merge {ids?}` (into the layer highlighted last, keeping the
|
||||
|
||||
@@ -1391,7 +1391,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
Layer Options for several highlighted rows shows the first row's settings, and OK changes only the settings set in the dialog: each row keeps its own color, Template, Lock, Show, Print, Preview and Dim Images otherwise (`crates/ui-egui/src/dialogs/layer_options.rs` tests).
|
||||
As VectorCraft's own rule, a layer color (`layer.setProps`, `layer.new`, `layer.newSublayer`) or a Live Paint Gap Preview Color (`livePaint.gapOptions`) given as a hex color with an alpha part (`#rrggbbaa` or `#rgba`) is an error and changes nothing, instead of being set without its alpha. Regression tests: `a_layer_color_with_an_alpha_part_is_refused` in `crates/engine/src/tests/layers.rs` and `a_gap_color_with_an_alpha_part_is_refused` in `crates/engine/src/tests/build.rs`.
|
||||
Panel Options › Locate Selected Objects (beyond Illustrator, off by default): when the last selected object changes on the canvas or by a command, the panel opens the layers and groups around it and scrolls to its row, as Locate Object does, without highlighting the row; when Show Layers Only, a search or the filter leaves the object without a row, the panel opens no rows for it and scrolls as with the option off.
|
||||
With Panel Options › Show Layers Only on, Locate Object is named Locate Layer and highlights the layer that holds the selected object instead of the object's own row, which that mode does not list (help page: https://helpx.adobe.com/illustrator/desktop/manage-layers/create-and-organize-layers/locate-objects-in-the-layers-panel.html). As VectorCraft's own rules, the bottom bar's button and a row's menu are renamed too, the innermost sublayer holding the object is the one highlighted, a layer row locates itself, and the panel opens the layers around it (`locate_layer_highlights_the_layer_holding_the_object` in `crates/engine/src/tests/layers.rs`, `with_show_layers_only_locate_object_becomes_locate_layer` in `crates/ui-egui/src/panels/layers/tests.rs`).
|
||||
With Panel Options › Show Layers Only on, Locate Object is named Locate Layer and highlights the layer that holds the selected object instead of the object's own row, which that mode does not list (help page: https://helpx.adobe.com/illustrator/desktop/manage-layers/create-and-organize-layers/locate-objects-in-the-layers-panel.html). As VectorCraft's own rules, the bottom bar's button and a row's menu are renamed too, the innermost sublayer holding the object is the one highlighted, a layer row locates itself, and the panel opens the layers around it. Locate Object or Locate Layer run again on the row it already highlighted opens the layers around that row again and scrolls to it, VectorCraft's own rule (`locate_layer_highlights_the_layer_holding_the_object` in `crates/engine/src/tests/layers.rs`, `with_show_layers_only_locate_object_becomes_locate_layer` and `a_repeated_locate_reveals_the_row_it_already_highlighted` in `crates/ui-egui/src/panels/layers/tests.rs`).
|
||||
- **Drawing aids:** Smart Guides and snapping (moving, with the Selection, Group Selection or Direct Selection tool, and resizing by the bounding-box handles with the Selection or Free Transform tool, Shift and Alt too: the dragged corner or side lands on the other objects' anchors and centres ("anchor", "center") or lines up with their edges and centres (a line and "align"); with Smart Guides › Spacing Guides, a moved selection that lines up with nothing along an axis lands as far from its neighbour as two other objects of its row or column are apart, or halfway between its two neighbours, the equal gaps marked; with View › Snap to Grid on, a moved selection lands on the grid instead, by whichever of its edges is nearest a gridline on each axis (the center does not snap), #740, #1816; the Rotate, Scale, Shear and Reflect tools drag from the anchor they grab and snap the pointer the same way, so a corner dragged onto another object's anchor scales exactly onto it, #482; anchors dragged with Direct Selection: the one pressed on lands on other anchors, its own path's that stay put among them, on path segments or in line with them, the others following, Shift keeps 45° steps, and with Smart Guides off Snap to Point pulls it onto anchors; the Artboard tool snaps artboards, and their bleed, to other artboards, bleeds and art, the grid or whole pixels while moving, copying and resizing them, and the Transform panel shows and edits the active artboard's X/Y/W/H; drawn points, #506: hovering shows where the press goes, the point lands on the other objects' anchors, centres and paths ("anchor", "center", "path") or lines up with their anchors, edges and centres ("align"), the Pen's on the path being drawn too, near a construction guide through the anchor before it on that guide (Preferences › Smart Guides › Construction Guides and Angles), and with Shift kept to its 45° step or a square's diagonal it slides along that way into line; the targets are gathered once per document state, from the art in the window, and the anchors, centres and lines near the pointer are found by bisection, so hovering never rescans the document), guides dragged out of the rulers (#451: they snap as moved guides do, Shift to the ruler's ticks; with the Artboard tool they are artboard guides, which run across their artboard only and move, copy and delete with it, `guide.add {artboard}`) that the Selection, Direct Selection and Group Selection tools then pick and drag (#414: the selected guides highlight and move together, Alt copies them, Shift snaps the dragged one to the ticks, otherwise it snaps to pixels, the grid or the edges, centres (so the sides' midpoints) and anchors of the art and the artboards, or with Smart Guides off Snap to Point pulls it onto anchors; Shift-clicked they join the selected art, and Shift-added art keeps them, so guides and art are selected together in either order, Delete then deleting both in one step; the arrow keys nudge them, Delete deletes them, dragging one back onto its ruler deletes it, Lock Guides and Hide Guides leave them alone; `guide.list`, `guide.select`, `guide.move` and `guide.remove` reach agents), a right-click on either ruler or the origin box to pick the document's units (the current one checked; `document.setUnits`, one undo step, #528), and Draw Normal / Behind / Inside modes. Smart Guides: a point drawn with the Pen or a shape tool, and an anchor dragged with Direct Selection, snaps to where paths and ruler guides cross, labelled "intersect" (#1658, part of #1602; a moved selection's own anchors don't, except the anchor the Selection tool grabbed it by). A selection the Selection tool grabs by one of its anchors snaps that anchor onto the other objects' paths ("path"), and where a path crosses another path or a ruler guide ("intersect"), in the order Direct Selection uses for a dragged anchor; when the anchor lands on a path, the selection's bounds do not also line up with other objects (#7411). The archived 2007 [user guide](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf#page=55) (page 49) says Smart Guides align the pointer of a moved object to existing paths. Snapping onto paths only when the selection was grabbed by an anchor is VectorCraft's own rule; a selection grabbed anywhere else still lines its bounds up. Tests: `select::tests::a_move_grabbed_by_an_anchor_lands_it_on_another_path`, `a_move_grabbed_by_an_anchor_lands_it_where_paths_cross` and `a_move_grabbed_by_an_anchor_lands_it_where_a_path_crosses_a_ruler_guide`. With Smart Guides › Measurement Labels on, the Line Segment tool labels the segment being drawn with its distance, angle and X and Y offsets (`D`, `Angle`, `dX`, `dY`), and the Pen, Curvature and Smart Pen tools label their rubber band the same way when Enable Rubber Band is on (#2983).
|
||||
A move that Shift keeps level, upright or diagonal stays on that line when it snaps, with the Selection, Group Selection or Direct Selection tool. It slides along the line until the selection lands on the grid or on whole pixels, lines up with the other objects or is spaced evenly with them, or until the line passes an anchor or crosses a ruler guide near the point the selection was grabbed by. A level or upright move snaps along its own axis only.
|
||||
Snap to Last Location: with Smart Guides on and Preferences › Smart Guides › Snap to Last Location on (off by default, VectorCraft's own choice), a selection moved by dragging with the Selection, Group Selection or Direct Selection tool, Shift too, goes back to where the move began while it is within Snapping Tolerance of it, labeled "last location"; an Alt copy is not pulled back onto its original, and with View › Snap to Grid or Snap to Pixel on the move snaps to the grid or to whole pixels instead (`prefs.set` key `snapToLastLocation`). The public [Smart Guides options](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/smart-guides-options.html) page lists the option as snapping objects back to their previous position; the distance, the label, the copy rule and the grid and pixel rule are VectorCraft's own. Tests: `select::tests::snap_to_last_location_puts_a_move_back_where_it_began`, `select::tests::snap_to_pixel_wins_over_snap_to_last_location`, `direct::tests::snap_to_last_location_puts_a_path_moved_by_its_anchor_back`, `direct::tests::snap_to_pixel_wins_over_snap_to_last_location_for_a_path_moved_by_its_anchor`, `tests_prefs::snap_to_last_location_puts_a_dragged_square_back`.
|
||||
|
||||
Reference in New Issue
Block a user