mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +01:00
Layers: Shift-click in the selection column selects the art of a range of rows
After a selection square is clicked, Shift-clicking another selects the
art of every row listed from the last square clicked to this one, down or
up and across sublayers and groups. Shift+Ctrl/Cmd-click adds that art to
the selection. Hidden and locked rows and art outside the isolated group
are left out, and a range does not move where the next Shift-click
starts. Before any square is clicked, Shift-click still adds one row's
art or takes it out. Ctrl/Cmd-click on a square now does the same; it
used to select the row's art alone, as a plain click does.
The panel menu's Select Art of Highlighted Rows selects the art of the
highlighted rows by the same rules.
- layer.selectAll takes {range: [id...], add?}, gathered with
Selection::target_range as the target circles' ranges are.
- layer.selectHighlighted {add?} is new. Neither is an undo step, and
the highlighted rows stay.
- Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
1 parent
5b0a96be26
commit
36d3cd0a15
10 files changed
+284
-22
No files matched your search
@@ -102,10 +102,19 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Select Art",
|
||||
[],
|
||||
None,
|
||||
"{id, add?: bool} the Layers panel's selection column: select the visible, unlocked art of a layer (its sublayers' too), or the object itself; `add` (Shift-click) adds it to the selection, or removes it when it is all selected already → {selected: [..]}",
|
||||
"{id, add?: bool} or {range: [id…], add?: bool} the Layers panel's selection column: select the visible, unlocked art of a layer (its sublayers' too), or the object itself; `add` (Shift-click with no square clicked before, or Ctrl/Cmd-click) adds it to the selection, or removes it when it is all selected already. `range` (Shift-click, the rows from the last square clicked to this one): the art of every listed row that is visible, unlocked and inside the isolated art is selected, or added to the selection with `add` (Shift+Ctrl/Cmd-click); a range with no such row is an error. Not an undo step; the highlighted rows stay → {selected: [..]} (with `range`: {range, selected})",
|
||||
has_doc,
|
||||
select_art
|
||||
),
|
||||
cmd!(
|
||||
"layer.selectHighlighted",
|
||||
"Select Art of Highlighted Rows",
|
||||
[],
|
||||
None,
|
||||
"{add?: bool} select the art of the Layers panel's highlighted rows, as clicking each row's selection square does: a layer's or sublayer's visible, unlocked art (its sublayers' too), or the group or object itself; hidden and locked rows and rows outside the isolated art are left out. `add` adds the art to the selection. No highlighted row, or none that is visible and unlocked, is an error. Not an undo step; the highlighted rows stay → {rows, selected: [..]}",
|
||||
has_doc,
|
||||
select_highlighted
|
||||
),
|
||||
cmd!(
|
||||
"layer.move",
|
||||
"Move Rows",
|
||||
@@ -753,6 +762,11 @@ fn in_isolation(doc: &Document, isolation: Option<NodeId>, id: NodeId) -> bool {
|
||||
/// The selection column: select a row's art.
|
||||
fn select_art(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "layer.selectAll";
|
||||
if let Some(ids) = ids_param(p, "range", C)? {
|
||||
let add = switch_or(p, "add", false, C)?;
|
||||
let (range, selected) = select_rows_art(s, ids, add, C, "no row in the range is visible, unlocked and inside the isolated art")?;
|
||||
return Ok(json!({ "range": range, "selected": selected }));
|
||||
}
|
||||
let id = object_param(p, "id", C)?.ok_or_else(|| bad(C, "missing id"))?;
|
||||
let add = switch_or(p, "add", false, C)?;
|
||||
let st = s.doc()?;
|
||||
@@ -789,6 +803,51 @@ fn select_art(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({ "selected": st.selection.objects.iter().map(|i| i.0).collect::<Vec<_>>() }))
|
||||
}
|
||||
|
||||
/// Select Art of Highlighted Rows: the art of the highlighted rows, as their selection squares
|
||||
/// select it.
|
||||
fn select_highlighted(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const C: &str = "layer.selectHighlighted";
|
||||
let add = switch_or(p, "add", false, C)?;
|
||||
let rows = s.doc()?.highlighted_rows();
|
||||
if rows.is_empty() {
|
||||
return Err(bad(C, "no row is highlighted"));
|
||||
}
|
||||
let (rows, selected) = select_rows_art(s, rows, add, C, "no highlighted row is visible, unlocked and inside the isolated art")?;
|
||||
Ok(json!({ "rows": rows, "selected": selected }))
|
||||
}
|
||||
|
||||
/// Selects the art of the Layers panel rows `ids` (at most [`MAX_ROWS`]), or adds it to the
|
||||
/// selection with `add`: each row that is visible, unlocked and inside the isolated art (or is the
|
||||
/// isolated layer) gives what its selection square selects, a layer's visible, unlocked art (its
|
||||
/// sublayers' too) or the group or object itself, as [`Selection::target_range`] gathers it for a
|
||||
/// range of target circles. Nothing is targeted and the highlighted rows stay. Without such a row it
|
||||
/// is the error `none`. Returns the rows used and the selected objects.
|
||||
///
|
||||
/// [`Selection::target_range`]: vectorcraft_doc::Selection::target_range
|
||||
fn select_rows_art(s: &mut Session, mut ids: Vec<NodeId>, add: bool, c: &str, none: &str) -> Result<(Vec<u64>, Vec<u64>)> {
|
||||
ids.truncate(MAX_ROWS);
|
||||
let rows = {
|
||||
let st = s.doc()?;
|
||||
// Measures the locked artboards once for every row, not once per row.
|
||||
let editable = st.doc.editable();
|
||||
ids.retain(|id| {
|
||||
st.doc.node(*id).is_some_and(|n| {
|
||||
let isolated_layer = st.isolation == Some(*id) && n.is_layer();
|
||||
!n.is_ruler_guide() && editable(*id) && (isolated_layer || in_isolation(&st.doc, st.isolation, *id))
|
||||
})
|
||||
});
|
||||
st.layer_rows.clone()
|
||||
};
|
||||
if ids.is_empty() {
|
||||
return Err(bad(c, none));
|
||||
}
|
||||
s.select(|d, sel| sel.target_range(d, &ids, add))?;
|
||||
let st = s.doc_mut()?;
|
||||
// The selection column leaves the highlighted rows as they are.
|
||||
st.layer_rows = rows;
|
||||
Ok((ids.iter().map(|i| i.0).collect(), st.selection.objects.iter().map(|i| i.0).collect()))
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Place {
|
||||
Above,
|
||||
|
||||
@@ -243,6 +243,7 @@ pub(super) const ALLOWED: &[&str] = &[
|
||||
"layer.releaseToLayersBuild",
|
||||
"layer.reverse",
|
||||
"layer.selectAll",
|
||||
"layer.selectHighlighted",
|
||||
"layer.setCurrent",
|
||||
"layer.setProps",
|
||||
"layer.showAll",
|
||||
|
||||
@@ -390,6 +390,105 @@ fn the_selection_column_selects_a_rows_art_and_shift_adds_or_removes_it() {
|
||||
assert_eq!(ids_sel(&run(&mut s, "layer.target", json!({"id": layer.0}))), vec![c, a, g]);
|
||||
}
|
||||
|
||||
/// The selection as a sorted list.
|
||||
fn sorted_sel(s: &Session) -> Vec<NodeId> {
|
||||
let mut ids = s.doc().unwrap().selection.objects.clone();
|
||||
ids.sort();
|
||||
ids
|
||||
}
|
||||
|
||||
/// The art the selection squares of `rows` select, each clicked alone, put together and sorted.
|
||||
/// Leaves nothing selected.
|
||||
fn each_rows_art(s: &mut Session, rows: &[NodeId]) -> Vec<NodeId> {
|
||||
run(s, "select.none", json!({}));
|
||||
let mut art = vec![];
|
||||
for row in rows {
|
||||
art.extend(ids_sel(&run(s, "layer.selectAll", json!({"id": row.0}))));
|
||||
}
|
||||
art.sort();
|
||||
art.dedup();
|
||||
run(s, "select.none", json!({}));
|
||||
art
|
||||
}
|
||||
|
||||
/// `layer.selectAll` with `range` (a Shift-click from the last selection square clicked) selects
|
||||
/// the art of every row in the range, across the sublayer and the group, as each row's square
|
||||
/// selects it; hidden and locked rows are left out, and `add` adds to the selection. The
|
||||
/// highlighted rows stay, and no undo step is recorded.
|
||||
#[test]
|
||||
fn the_selection_column_selects_the_art_of_a_range_of_rows() {
|
||||
let mut s = session();
|
||||
let (layer, sub, a, g, b, c) = tree(&mut s);
|
||||
run(&mut s, "layer.setCurrent", json!({"id": sub.0}));
|
||||
let undo = undos(&s);
|
||||
// The rows top down: the layer, the sublayer, the group, its rectangle, then a and c.
|
||||
let range = [g, b, a, c];
|
||||
let want = each_rows_art(&mut s, &range);
|
||||
let reply = run(&mut s, "layer.selectAll", json!({"range": range.map(|r| r.0)}));
|
||||
assert_eq!(sorted_sel(&s), want, "the group, its member's row, the sublayer's rectangle and the top layer's rectangle");
|
||||
assert!(want.contains(&a) && want.contains(&c), "{want:?}");
|
||||
assert_eq!(ids_sel(&reply).len(), s.doc().unwrap().selection.objects.len());
|
||||
assert_eq!(s.doc().unwrap().highlighted_rows(), vec![sub], "the highlighted row stays");
|
||||
assert_eq!(undos(&s), undo, "a selection change is not an undo step");
|
||||
// A range given bottom up selects the same art.
|
||||
run(&mut s, "layer.selectAll", json!({"range": [c.0, a.0, b.0, g.0]}));
|
||||
assert_eq!(sorted_sel(&s), want);
|
||||
// `add` keeps what was selected.
|
||||
run(&mut s, "select.set", json!({"ids": [c.0]}));
|
||||
run(&mut s, "layer.selectAll", json!({"range": [a.0], "add": true}));
|
||||
let got = sorted_sel(&s);
|
||||
assert!(got.len() == 2 && got.contains(&a) && got.contains(&c), "{got:?}");
|
||||
// A range holding a layer row takes that layer's art, its sublayer's too.
|
||||
run(&mut s, "layer.selectAll", json!({"range": [layer.0, sub.0]}));
|
||||
assert_eq!(sorted_sel(&s), each_rows_art(&mut s, &[layer]));
|
||||
// Locked and hidden rows are left out.
|
||||
run(&mut s, "layer.setProps", json!({"ids": [a.0], "locked": true}));
|
||||
run(&mut s, "layer.setProps", json!({"ids": [c.0], "visible": false}));
|
||||
run(&mut s, "layer.selectAll", json!({"range": range.map(|r| r.0)}));
|
||||
let got = sorted_sel(&s);
|
||||
assert!(!got.is_empty() && !got.contains(&a) && !got.contains(&c), "{got:?}");
|
||||
// A range of only hidden and locked rows changes nothing and says why.
|
||||
run(&mut s, "select.set", json!({"ids": [g.0]}));
|
||||
assert!(s.execute("layer.selectAll", &json!({"range": [a.0, c.0]})).is_err());
|
||||
assert_eq!(sorted_sel(&s), vec![g]);
|
||||
}
|
||||
|
||||
/// `layer.selectHighlighted` selects the art of the highlighted rows, as their selection squares
|
||||
/// do, leaving out hidden and locked rows; `add` adds it. The highlighted rows stay, no undo step is
|
||||
/// recorded, and with no row highlighted it is an error.
|
||||
#[test]
|
||||
fn select_highlighted_selects_the_art_of_the_highlighted_rows() {
|
||||
let mut s = session();
|
||||
let (_, _, a, g, _, c) = tree(&mut s);
|
||||
let want = each_rows_art(&mut s, &[g, c]);
|
||||
run(&mut s, "layer.highlight", json!({"ids": [g.0, c.0], "mode": "set"}));
|
||||
let rows = s.doc().unwrap().highlighted_rows();
|
||||
let undo = undos(&s);
|
||||
run(&mut s, "layer.selectHighlighted", json!({}));
|
||||
assert_eq!(sorted_sel(&s), want);
|
||||
assert_eq!(s.doc().unwrap().highlighted_rows(), rows, "the highlighted rows stay");
|
||||
assert_eq!(undos(&s), undo, "a selection change is not an undo step");
|
||||
// `add` keeps what was selected.
|
||||
run(&mut s, "select.set", json!({"ids": [a.0]}));
|
||||
// Selecting art in another layer let go of the highlighted rows.
|
||||
run(&mut s, "layer.highlight", json!({"ids": [g.0, c.0], "mode": "set"}));
|
||||
run(&mut s, "layer.selectHighlighted", json!({"add": true}));
|
||||
let mut with_a = want.clone();
|
||||
with_a.push(a);
|
||||
with_a.sort();
|
||||
assert_eq!(sorted_sel(&s), with_a);
|
||||
// A hidden row is left out.
|
||||
run(&mut s, "layer.setProps", json!({"ids": [c.0], "visible": false}));
|
||||
run(&mut s, "layer.highlight", json!({"ids": [g.0, c.0], "mode": "set"}));
|
||||
run(&mut s, "layer.selectHighlighted", json!({}));
|
||||
assert!(!sorted_sel(&s).contains(&c));
|
||||
// With no row highlighted, nothing changes.
|
||||
run(&mut s, "layer.highlight", json!({"ids": [], "mode": "set"}));
|
||||
run(&mut s, "select.set", json!({"ids": [a.0]}));
|
||||
assert!(s.execute("layer.selectHighlighted", &json!({})).is_err());
|
||||
assert_eq!(sorted_sel(&s), vec![a]);
|
||||
}
|
||||
|
||||
/// The rows of [`column_start`]: [`tree`]'s, plus a rectangle `o` on a second layer and an empty
|
||||
/// third layer `e`.
|
||||
#[derive(Clone, Copy)]
|
||||
|
||||
@@ -179,6 +179,8 @@ pub struct LayersUi {
|
||||
pub focused: bool,
|
||||
/// The target circle clicked last, with its document's `uid`: where a Shift-click on another circle starts.
|
||||
pub target_anchor: Option<(u64, NodeId)>,
|
||||
/// The selection square clicked last, with its document's `uid`: where a Shift-click on another square starts.
|
||||
pub art_anchor: Option<(u64, NodeId)>,
|
||||
/// The active document's rows with the [`LayerRows::key`] they were listed at.
|
||||
rows: Option<(u64, Tracked<LayerRows>)>,
|
||||
}
|
||||
@@ -188,7 +190,7 @@ impl Default for LayersUi {
|
||||
fn default() -> Self {
|
||||
let mut filter = LayerFilter::default();
|
||||
filter.by = FilterBy::Objects;
|
||||
Self { filter, rename: None, focused: false, target_anchor: None, rows: None }
|
||||
Self { filter, rename: None, focused: false, target_anchor: None, art_anchor: None, rows: None }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +216,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let mut footer = Vec::new();
|
||||
let mut picks = Vec::new();
|
||||
let mut target_click = None;
|
||||
let mut art_click = None;
|
||||
let thumbnails = thumbs::layer_thumbnails(ui.ctx(), uid);
|
||||
// A drag's previews keep the shown pictures; the rows render once it ends.
|
||||
thumbnails.hold(app.session.active().is_some_and(|st| st.interaction.is_some()) || app.session.tool_busy());
|
||||
@@ -232,7 +235,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
.blend_rows(false)
|
||||
.deletable(true)
|
||||
.takes_drop::<cells::ArtDrag>(cells::accepts_art(&tree))
|
||||
.trailing(|id, info| cells::build(&tree, id, info), |id, shown| cells::output(&mut picks, &mut target_click, id, shown))
|
||||
.trailing(|id, info| cells::build(&tree, id, info), |id, shown| cells::output(&mut picks, &mut target_click, &mut art_click, id, shown))
|
||||
.row_menu(|target| controls::row_menu(&tree, target))
|
||||
.footer(|ui| controls::footer(&tree, ui, &mut footer))
|
||||
.document(uid);
|
||||
@@ -246,13 +249,20 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
// A Shift-click starts at the last circle clicked in this document, else at the targeted row.
|
||||
let anchor = app.ui.layers_ui.target_anchor.filter(|(doc, _)| *doc == uid).map(|(_, id)| id);
|
||||
let target = target_click.map(|(id, mods)| (id, rows::target_click(&tree, &filter, anchor, id, mods)));
|
||||
// A Shift-click on a selection square starts at the last square clicked in this document.
|
||||
let art_anchor = app.ui.layers_ui.art_anchor.filter(|(doc, _)| *doc == uid).map(|(_, id)| id);
|
||||
let art = art_click.map(|(id, mods)| (id, rows::art_click(&tree, &filter, art_anchor, id, mods)));
|
||||
app.ui.layers_ui.filter = filter;
|
||||
if let Some((id, (_, true))) = &target {
|
||||
app.ui.layers_ui.target_anchor = Some((uid, *id));
|
||||
}
|
||||
if let Some((id, (_, true))) = &art {
|
||||
app.ui.layers_ui.art_anchor = Some((uid, *id));
|
||||
}
|
||||
app.ui.layers_ui.focused = output.focused;
|
||||
rows::apply(app, output.events);
|
||||
for (c, p) in footer.into_iter().chain(picks).chain(target.map(|(_, (command, _))| command)) {
|
||||
let clicks = art.into_iter().chain(target).map(|(_, (command, _))| command);
|
||||
for (c, p) in footer.into_iter().chain(picks).chain(clicks) {
|
||||
app.run(&c, p).ok();
|
||||
}
|
||||
// The panel's own commands reveal nothing for the selection they made: Locate Selected Objects
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
//! ([`rows::target_click`](super::rows::target_click)); dragging it carries the appearance
|
||||
//! ([`PanelDrag::Appearance`]) onto another row's circle (Alt copies it) or the trash. A circle
|
||||
//! lights up while another row's appearance is held over it.
|
||||
//! - The selection square selects the row's art (Shift adds or removes); a row whose art is
|
||||
//! - The selection square selects the row's art, with the modifier rules of
|
||||
//! [`rows::art_click`](super::rows::art_click) (Shift selects a range of rows); a row whose art is
|
||||
//! selected shows it in its layer's colour, a row holding selected art a small one, and dragging
|
||||
//! either onto another row moves the selected art there (Alt copies it).
|
||||
//!
|
||||
@@ -42,8 +43,9 @@ pub(super) struct ArtDrag(pub(super) Vec<NodeId>);
|
||||
enum CellPick {
|
||||
/// The circle was clicked with these modifiers.
|
||||
Target(Mods),
|
||||
/// The square was clicked: select the row's art (Shift adds or removes).
|
||||
SelectArt { add: bool },
|
||||
/// The square was clicked with these modifiers: select the row's art, by the rules of
|
||||
/// [`rows::art_click`](super::rows::art_click).
|
||||
SelectArt(Mods),
|
||||
/// Another row's appearance was dropped on the circle (Alt copies it).
|
||||
TakeAppearance { source: NodeId, copy: bool },
|
||||
}
|
||||
@@ -248,7 +250,7 @@ impl Component for SelectionSquare {
|
||||
return;
|
||||
}
|
||||
if let Some(activation) = cx.activation() {
|
||||
self.pick = Some(CellPick::SelectArt { add: activation.mods.shift });
|
||||
self.pick = Some(CellPick::SelectArt(activation.mods));
|
||||
}
|
||||
if (self.selected || self.holds) && !self.art.is_empty() && primary_drag_start(cx) {
|
||||
cx.start_drag(ArtDrag(self.art.clone()), DragPreview::None);
|
||||
@@ -382,14 +384,21 @@ pub(super) fn build(tree: &DocLayers<'_>, row: &RowId, info: &LayerInfo) -> Cell
|
||||
}
|
||||
}
|
||||
|
||||
/// What row `row`'s cells reported: the commands `layer.selectAll` and `appearance.transfer` on the row's node, added to
|
||||
/// `out`, and a click on its target circle with its modifiers, which the panel resolves once it knows its rows.
|
||||
pub(super) fn output(out: &mut Vec<(String, Value)>, target: &mut Option<(NodeId, Mods)>, row: &RowId, shown: CellsOutput) {
|
||||
/// What row `row`'s cells reported: the command `appearance.transfer` on the row's node, added to `out`, and a click on
|
||||
/// its target circle (`target`) or its selection square (`art`) with its modifiers, which the panel resolves once it
|
||||
/// knows its rows.
|
||||
pub(super) fn output(
|
||||
out: &mut Vec<(String, Value)>,
|
||||
target: &mut Option<(NodeId, Mods)>,
|
||||
art: &mut Option<(NodeId, Mods)>,
|
||||
row: &RowId,
|
||||
shown: CellsOutput,
|
||||
) {
|
||||
let RowId::Node(id) = *row else { return };
|
||||
for pick in shown.picks {
|
||||
match pick {
|
||||
CellPick::Target(mods) => *target = Some((id, mods)),
|
||||
CellPick::SelectArt { add } => out.push(("layer.selectAll".to_string(), json!({"id": id.0, "add": add}))),
|
||||
CellPick::SelectArt(mods) => *art = Some((id, mods)),
|
||||
CellPick::TakeAppearance { source, copy } => {
|
||||
out.push(("appearance.transfer".to_string(), json!({"source": source.0, "target": id.0, "copy": copy})));
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@ fn items(app: &VectorcraftApp) -> Vec<Item> {
|
||||
} else {
|
||||
command("layer.locate", json!({}), tl!("Locate Object"), has_sel)
|
||||
},
|
||||
command("layer.selectHighlighted", json!({}), tl!("Select Art of Highlighted Rows"), !rows.is_empty()),
|
||||
save_selection(app),
|
||||
Item::Separator,
|
||||
command("layer.merge", json!({}), tl!("Merge Selected"), rows.len() >= 2),
|
||||
|
||||
@@ -156,20 +156,38 @@ pub(super) fn full_layers(doc: &Document, sel: &HashSet<NodeId>) -> HashSet<Node
|
||||
/// whether the click moves the anchor to `id`: every click but a Shift range.
|
||||
pub(super) fn target_click(tree: &DocLayers<'_>, filter: &LayerFilter, anchor: Option<NodeId>, id: NodeId, mods: Mods) -> ((String, Value), bool) {
|
||||
if mods.shift
|
||||
&& let Some(start) = anchor.or(tree.state().selection.target)
|
||||
&& let Some(range) = anchor.or(tree.state().selection.target).and_then(|start| listed_range(tree, filter, start, id))
|
||||
{
|
||||
let order = listed_nodes(tree, filter);
|
||||
let at = |k: NodeId| order.iter().position(|r| *r == k);
|
||||
if let (Some(i), Some(j)) = (at(start), at(id)) {
|
||||
let range: Vec<u64> = order.get(i.min(j)..=i.max(j)).unwrap_or_default().iter().map(|r| r.0).collect();
|
||||
let params = if mods.cmd { json!({"range": range, "add": true}) } else { json!({"range": range}) };
|
||||
return (("layer.target".into(), params), false);
|
||||
}
|
||||
let params = if mods.cmd { json!({"range": range, "add": true}) } else { json!({"range": range}) };
|
||||
return (("layer.target".into(), params), false);
|
||||
}
|
||||
let params = if mods.cmd { json!({"id": id.0, "add": true}) } else { json!({"id": id.0}) };
|
||||
(("layer.target".into(), params), true)
|
||||
}
|
||||
|
||||
/// The `layer.selectAll` of a click with `mods` on the selection square of `id`. A plain click selects the row's art.
|
||||
/// Shift selects the art of every row `filter` lists from `anchor` (the last square clicked) to it, and Shift+Ctrl/Cmd
|
||||
/// adds that art to the selection. With no anchor listed, Shift adds the row's art or removes it when it is all
|
||||
/// selected, and so does Ctrl/Cmd. With it, whether the click moves the anchor to `id`: every click but a Shift range.
|
||||
pub(super) fn art_click(tree: &DocLayers<'_>, filter: &LayerFilter, anchor: Option<NodeId>, id: NodeId, mods: Mods) -> ((String, Value), bool) {
|
||||
if mods.shift
|
||||
&& let Some(range) = anchor.and_then(|start| listed_range(tree, filter, start, id))
|
||||
{
|
||||
let params = if mods.cmd { json!({"range": range, "add": true}) } else { json!({"range": range}) };
|
||||
return (("layer.selectAll".into(), params), false);
|
||||
}
|
||||
let params = if mods.shift || mods.cmd { json!({"id": id.0, "add": true}) } else { json!({"id": id.0}) };
|
||||
(("layer.selectAll".into(), params), true)
|
||||
}
|
||||
|
||||
/// The rows `filter` lists from `start` to `end`, both included, top-down; `None` when either is not listed.
|
||||
fn listed_range(tree: &DocLayers<'_>, filter: &LayerFilter, start: NodeId, end: NodeId) -> Option<Vec<u64>> {
|
||||
let order = listed_nodes(tree, filter);
|
||||
let at = |k: NodeId| order.iter().position(|r| *r == k);
|
||||
let (i, j) = (at(start)?, at(end)?);
|
||||
Some(order.get(i.min(j)..=i.max(j)).unwrap_or_default().iter().map(|r| r.0).collect())
|
||||
}
|
||||
|
||||
/// The layer, group and object rows the panel over `tree` lists under `filter`, top-down: the children of open rows,
|
||||
/// and while the filter is on every row it keeps and every row holding one, open or not.
|
||||
fn listed_nodes(tree: &DocLayers<'_>, filter: &LayerFilter) -> Vec<NodeId> {
|
||||
|
||||
@@ -562,6 +562,65 @@ fn the_target_circle_anchor_does_not_carry_over_to_another_document() {
|
||||
assert_eq!(targeted(&panel.app()), (Some(b2), vec![b2]));
|
||||
}
|
||||
|
||||
/// Shift-clicking a selection square selects the art of every row from the last square clicked to
|
||||
/// it, down or up and across a sublayer and a group, leaving out locked and hidden rows, and
|
||||
/// Shift+Ctrl/Cmd adds that art. A plain click selects one row's art, and Ctrl/Cmd adds it or takes
|
||||
/// it out again.
|
||||
#[test]
|
||||
fn shift_clicking_a_selection_square_selects_the_art_of_a_range_of_rows() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use egui::Modifiers;
|
||||
let (mut app, [_, _, g, b, a, c]) = nested();
|
||||
for (id, name) in [(g, "G"), (b, "B"), (a, "A"), (c, "C")] {
|
||||
name_row(&mut app, id, name);
|
||||
}
|
||||
// Rows top down: the layer, the sublayer, G, B (in G), A, then C on the layer itself.
|
||||
let mut panel = Panel::new(app, show);
|
||||
panel.click_with("Select art of A", Modifiers::NONE);
|
||||
assert_eq!(targeted(&panel.app()), (None, vec![a]), "a plain click selects one row's art");
|
||||
panel.click_with("Select art of C", Modifiers::SHIFT);
|
||||
let (_, sel) = targeted(&panel.app());
|
||||
assert!(sel.len() == 2 && sel.contains(&a) && sel.contains(&c), "a range down, out of the sublayer: {sel:?}");
|
||||
// A range starts at the last square clicked, not at the end of the last range.
|
||||
panel.click_with("Select art of G", Modifiers::SHIFT);
|
||||
let (_, sel) = targeted(&panel.app());
|
||||
assert!(sel.contains(&g) && sel.contains(&a) && !sel.contains(&c), "a range up, across the group: {sel:?}");
|
||||
// Shift+Ctrl/Cmd adds a range: from A down to C.
|
||||
panel.click_with("Select art of C", Modifiers::SHIFT | Modifiers::COMMAND);
|
||||
let (_, sel) = targeted(&panel.app());
|
||||
assert!(sel.contains(&g) && sel.contains(&a) && sel.contains(&c), "{sel:?}");
|
||||
// Ctrl/Cmd takes one row's art out again.
|
||||
panel.click_with("Select art of C", Modifiers::COMMAND);
|
||||
let (_, sel) = targeted(&panel.app());
|
||||
assert!(sel.contains(&g) && !sel.contains(&c), "{sel:?}");
|
||||
// Locked and hidden rows in a range stay unselected.
|
||||
panel.app().session.execute("layer.setProps", &json!({"ids": [a.0], "locked": true})).unwrap();
|
||||
panel.app().session.execute("layer.setProps", &json!({"ids": [b.0], "visible": false})).unwrap();
|
||||
panel.click_with("Select art of G", Modifiers::NONE);
|
||||
panel.click_with("Select art of C", Modifiers::SHIFT);
|
||||
let (_, sel) = targeted(&panel.app());
|
||||
assert!(sel.contains(&g) && sel.contains(&c) && !sel.contains(&a) && !sel.contains(&b), "{sel:?}");
|
||||
}
|
||||
|
||||
/// With no selection square clicked yet, Shift-clicking one adds its row's art, or takes it out
|
||||
/// when it is all selected, and that square becomes where the next Shift-click starts.
|
||||
#[test]
|
||||
fn shift_clicking_the_first_selection_square_adds_or_removes_one_row() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use egui::Modifiers;
|
||||
let (mut app, [_, _, g, _, a, c]) = nested();
|
||||
for (id, name) in [(g, "G"), (a, "A"), (c, "C")] {
|
||||
name_row(&mut app, id, name);
|
||||
}
|
||||
app.session.execute("select.set", &json!({"ids": [a.0, c.0]})).unwrap();
|
||||
let mut panel = Panel::new(app, show);
|
||||
panel.click_with("Select art of A", Modifiers::SHIFT);
|
||||
assert_eq!(targeted(&panel.app()), (None, vec![c]), "a selected row's art is taken out");
|
||||
panel.click_with("Select art of C", Modifiers::SHIFT);
|
||||
let (_, sel) = targeted(&panel.app());
|
||||
assert!(sel.contains(&a) && sel.contains(&c) && !sel.contains(&g), "the range from A to C: {sel:?}");
|
||||
}
|
||||
|
||||
/// The rows among `rows` whose selection square is full-sized, then those whose square is the
|
||||
/// small one, in the order given.
|
||||
fn squares(app: &VectorcraftApp, rows: &[NodeId]) -> (Vec<NodeId>, Vec<NodeId>) {
|
||||
@@ -598,7 +657,7 @@ fn a_layer_with_all_its_art_selected_shows_the_full_square() {
|
||||
assert_eq!(squares(&panel.app(), &rows), (vec![sub, g, a], vec![layer]), "the sublayer, its group and rectangle full, the layer small");
|
||||
panel.click_with("Select art of Top", Modifiers::NONE);
|
||||
assert_eq!(squares(&panel.app(), &rows), (vec![layer, sub, g, a, c], vec![]), "the layer and the sublayer full, with each row's art");
|
||||
panel.click_with("Select art of A", Modifiers::SHIFT);
|
||||
panel.click_with("Select art of A", Modifiers::COMMAND);
|
||||
assert_eq!(squares(&panel.app(), &rows), (vec![g, c], vec![layer, sub]), "one rectangle let go: the layer and the sublayer small again");
|
||||
// Locked art cannot be selected, so it does not keep the layer's square small.
|
||||
panel.app().session.execute("layer.setProps", &json!({"ids": [c.0], "locked": true})).unwrap();
|
||||
|
||||
+6
-1
@@ -6506,7 +6506,12 @@ and `layerRows`, the rows highlighted in the panel.
|
||||
set|add|toggle}` is Shift-click (a range) and Ctrl/Cmd-click (toggle). Selecting art makes its layer current.
|
||||
Without `ids`, the panel commands below act on the highlighted rows, else on the current layer.
|
||||
- **Selection column**: `layer.selectAll {id, add?}` selects a row's visible, unlocked art (a layer's sublayers'
|
||||
too); `add` (Shift) adds it, or removes it when it's all selected. Alt-click on a layer's or sublayer's name runs
|
||||
too); `add` (Ctrl/Cmd, or Shift before any square was clicked) adds it, or removes it when it's all selected.
|
||||
`layer.selectAll {range: [id…], add?}` is a Shift-click on a square after another was clicked: the art of every
|
||||
row listed from the last square clicked to this one, across sublayers and groups, leaving out hidden and locked
|
||||
rows; Shift+Ctrl/Cmd adds it to the selection. A range does not move where the next Shift-click starts.
|
||||
`layer.selectHighlighted {add?}` (the panel menu's Select Art of Highlighted Rows) selects the art of the highlighted rows by the
|
||||
same rules. Neither is an undo step, and the highlighted rows stay. Alt-click on a layer's or sublayer's name runs
|
||||
`layer.selectAll {id}` and then `layer.setCurrent {id}`.
|
||||
- **Eye and lock**: `layer.setProps {ids?, visible?, locked?, name?}` for any rows, plus Layer Options for layers:
|
||||
`template` (also locks the layer and dims its images to 50% unless given), `printable`, `preview` (off: the layer
|
||||
|
||||
@@ -773,6 +773,7 @@ since 2026-10-01.
|
||||
- **Large Shift-marquee selections and Select › Inverse:** `select.toggle` and `select.add` with many ids (a Shift-drag marquee sends them together) go through the selection once instead of once per id, and Select › Inverse looks each object up in a set of the selected ones. The resulting selection, its order and the reply are the same as before. With 50,000 objects the selection step of toggling every object off took 528 to 655 ms before and 2.5 to 4.6 ms after in 7 runs, wall clock on a machine that was running other builds (`cargo run --release -p vectorcraft-engine --example selection_bench`). Regression tests: `add_all_does_what_adding_each_does` and `toggle_all_does_what_toggling_each_does` in `crates/doc/src/selection/tests.rs`, and `toggle_and_add_handle_each_listed_id_in_order` in `crates/engine/tests/it/selection_commands.rs`.
|
||||
- **Shift-click in the Layers panel's selection column on a large layer:** `layer.selectAll {id, add: true}` checks whether the row's art is all selected with a set of the selected objects, and removes or adds that art in one pass instead of once per object. The resulting selection, its order, the reply and the highlighted rows are the same as before. On a layer of 50,000 objects the whole command took a median of 733 ms before and 6.9 ms after when all of the layer's art was selected, and 369 ms before and 24 ms after when every other object was, in 7 runs each, wall clock on Linux while other builds were running (`cargo run --release -p vectorcraft-engine --example layer_select_bench`). Regression test: `a_shift_click_in_the_selection_column_matches_adding_or_removing_each_id` in `crates/engine/src/tests/layers.rs`.
|
||||
- **Ctrl/Cmd-click and Shift-click on Layers panel target circles (#8639):** the target circles follow the same modifier rules as the row names, as the help page describes for selecting objects in the Layers panel: Shift for adjacent objects, Ctrl or Command for non-adjacent ones ([Move objects to different layers](https://helpx.adobe.com/illustrator/desktop/manage-layers/create-and-organize-layers/move-objects-to-different-layers.html)). Ctrl/Cmd-click adds the item (a layer: its art) to the selection or takes it out, which Shift-click did before (#913); Shift-click selects the art of every row from the last circle clicked (else the targeted row) to this one, and Shift+Ctrl/Cmd-click adds it (`layer.target {range, add?}`). Hidden or locked art and art outside the isolated group in the range is left out, and nothing stays targeted. Regression tests: `clicking_a_target_circle_targets_the_layer` and `shift_clicking_a_target_circle_selects_a_range_of_rows` in `crates/ui-egui/src/panels/layers/tests.rs`.
|
||||
- **Shift-click in the Layers panel's selection column selects the art of a range of rows:** after a selection square is clicked, Shift-clicking another selects the art of every row listed from the last square clicked to this one, down or up and across sublayers and groups, and Shift+Ctrl/Cmd-click adds that art to the selection (`layer.selectAll {range, add?}`). Hidden and locked rows and art outside the isolated group are left out, and a range does not move where the next Shift-click starts. Ctrl/Cmd-click adds one row's art or takes it out, and so does Shift-click before any square was clicked. The panel menu's Select Art of Highlighted Rows (`layer.selectHighlighted`) selects the art of the highlighted rows by the same rules. These are VectorCraft's own rules. Regression tests: `shift_clicking_a_selection_square_selects_the_art_of_a_range_of_rows` and `shift_clicking_the_first_selection_square_adds_or_removes_one_row` in `crates/ui-egui/src/panels/layers/tests.rs`, `the_selection_column_selects_the_art_of_a_range_of_rows` and `select_highlighted_selects_the_art_of_the_highlighted_rows` in `crates/engine/src/tests/layers.rs`.
|
||||
- **Layers added to the selection from their target circles show as targeted (#8646):** with several items picked from their circles (nothing targeted), a layer or sublayer's circle shows its inner ring while all of its visible, unlocked art is selected, as an object's circle does while the object is selected. A layer is never selected itself, only its art, so its circle used to keep a single ring. Regression test: `a_layer_added_from_its_target_circle_shows_as_targeted` in `crates/ui-egui/src/panels/layers/tests.rs`.
|
||||
- **A targeted item with an appearance of its own shows both marks (#8711):** its target circle keeps the inner ring of a targeted item, with the appearance dot drawn smaller inside it and a gap between them, so not targeted, targeted, with an appearance and both look different, as the target icons in [Appearance attributes](https://helpx.adobe.com/illustrator/using/appearance-attributes.html) do. The dot used to cover the ring. Regression test: `a_targeted_circle_with_an_appearance_shows_both_ring_and_dot` in `crates/ui-egui/src/panels/layers/tests.rs`.
|
||||
- **Selection passes through raster effects:** clicks with the Selection, Direct Selection and Group Selection tools (Group Selection's repeated click included), the Selection tool's pointer and marquee, Direct Selection's marquee, pointer and anchor highlight, and Group Selection's marquee (E for enclosed objects included) leave out the area that a drop shadow, a glow, a blur or another raster effect paints beyond an object. A click on a shadow selects the object under it, or nothing over an empty canvas, a repeated Group Selection click there adds the groups of the object under it, and a press on the shadow of a selected object does not move it ([the help page](https://helpx.adobe.com/illustrator/using/selecting-objects.html)). Over a shadow, Direct Selection highlights only the anchors of the object under it, and Group Selection keeps its own pointer and highlights no anchor, as it does everywhere (VectorCraft's own rule). No setting changes this. This covers paths, groups, type, symbol instances and images. Regression tests: `crates/engine/src/tests/select_effects.rs`.
|
||||
|
||||
Reference in new issue
Block a user