feat(timeline): a click on a layer's name selects its artwork, as in Animate (M1)

layer.select gains select?: the layer becomes active with all of its artwork
at the playhead selected (nothing on a locked or hidden layer). The timeline's
name click passes it. ADR 0044 and the roadmap updated.
This commit is contained in:
Tanish Manku committed 2026-11-10 16:47:50 -07:00
1 parent a31a6b5aaa
commit 5f6efdbf12
4 files changed
+49 -8

No files matched your search

+10 -2
View File
@@ -2,7 +2,7 @@
use crate::params::*;
use crate::{CommandSpec, EngineError, MAX_FRAME, Result, Session};
use anicraft_doc::{Keyframe, Layer, LayerId, LayerKind, Tween, TweenKind, evaluate_layer_elements};
use anicraft_doc::{ElementId, Keyframe, Layer, LayerId, LayerKind, Tween, TweenKind, evaluate_layer_elements};
use serde_json::{Value, json};
use std::sync::Arc;
@@ -41,7 +41,7 @@ pub fn specs() -> Vec<CommandSpec> {
c("layer.toggle_visible", "Show/Hide Layer", "", None, "{layer?}", true, |s, p| toggle(s, p, |l| l.visible = !l.visible)),
c("layer.toggle_lock", "Lock/Unlock Layer", "", None, "{layer?}", true, |s, p| toggle(s, p, |l| l.locked = !l.locked)),
c("layer.toggle_outline", "Outline Layer", "", None, "{layer?}", true, |s, p| toggle(s, p, |l| l.outline = !l.outline)),
c("layer.select", "Select Layer", "", None, "{layer: id} or {index}", false, select_layer),
c("layer.select", "Select Layer", "", None, "{layer: id} or {index}, select?: bool (also select all of its artwork at the playhead, as a click on the layer's name does; nothing on a locked or hidden layer)", false, select_layer),
c("layer.move_up", "Move Layer Up", "Modify/Timeline", None, "{layer?}", true, |s, p| move_layer(s, p, -1)),
c("layer.move_down", "Move Layer Down", "Modify/Timeline", None, "{layer?}", true, |s, p| move_layer(s, p, 1)),
c("layer.toggle_mask", "Mask", "Modify/Timeline", None, "{layer?}", true, toggle_mask),
@@ -754,6 +754,14 @@ fn select_layer(s: &mut Session, p: &Value) -> Result<Value> {
if s.doc.timeline(s.scene).layer(id).is_none() {
return Err(EngineError::State(format!("no layer with id {}", id.0)));
}
// A click on a layer's name in Animate: the layer becomes active with all of its artwork at
// the playhead selected (ADR 0044).
if opt_bool(p, "select")? == Some(true) {
s.layer = id;
let ids: Vec<ElementId> = if s.selectable(id) { s.elements_on(id).iter().map(|e| e.id).collect() } else { Vec::new() };
s.selection = crate::Selection::only(id, ids);
return Ok(json!({"layer": id.0, "selected": s.selection.id_list()}));
}
if s.layer != id {
s.layer = id;
s.selection.clear();
+28
View File
@@ -534,3 +534,31 @@ fn selection_timings() {
let v = run(&mut s, "raw.select_rect", json!({"x0": 65, "y0": 65, "x1": 215, "y1": 215}));
eprintln!("a marquee selects {} parts on {} layers ({} cut)", s.selection.len(), s.selected_layers().len(), v["cut"]);
}
#[test]
fn clicking_a_layer_name_selects_its_artwork() {
let (mut s, top, bottom, a, b) = two_layers();
// Another element on Bottom: the click takes both.
run(&mut s, "layer.select", json!({"layer": bottom.0}));
let c = el_id(&run(&mut s, "draw.rect", json!({"x": 400, "y": 400, "w": 20, "h": 20})));
run(&mut s, "layer.select", json!({"layer": top.0}));
assert!(s.selection.is_empty(), "without `select`, as before");
let v = run(&mut s, "layer.select", json!({"layer": bottom.0, "select": true}));
assert_eq!(v["selected"], json!([b.0, c.0]));
assert_eq!(s.layer, bottom);
assert_eq!(s.selection.iter().collect::<Vec<_>>(), vec![(bottom, b), (bottom, c)]);
// Again on the same layer: still all of it. On a locked layer: active, nothing selected.
run(&mut s, "element.select", json!({"ids": [a.0]}));
run(&mut s, "layer.select", json!({"layer": top.0, "select": true}));
assert_eq!(s.selection.iter().collect::<Vec<_>>(), vec![(top, a)]);
run(&mut s, "layer.toggle_lock", json!({"layer": bottom.0}));
run(&mut s, "layer.select", json!({"layer": bottom.0, "select": true}));
assert_eq!(s.layer, bottom);
assert!(s.selection.is_empty());
// At a frame where the layer is empty, nothing is selected.
run(&mut s, "layer.toggle_lock", json!({"layer": bottom.0}));
run(&mut s, "timeline.insert_keyframe", json!({"layer": top.0, "frame": 5}));
run(&mut s, "timeline.goto", json!({"frame": 5}));
run(&mut s, "layer.select", json!({"layer": bottom.0, "select": true}));
assert!(s.selection.is_empty());
}
+8 -3
View File
@@ -60,6 +60,9 @@ nothing was copied.
* `element.select {ids, add?, layer?}` takes ids on any visible, unlocked layer (looking on
the active layer first, then top to bottom, or only on `layer`); the active layer becomes
the first id's layer unless it holds some of them.
* A click on a layer's name in the timeline makes it active and selects all of its artwork at
the playhead, as in Animate (`layer.select {layer, select: true}`; nothing on a locked or
hidden layer). Without `select`, `layer.select` only changes the active layer, as before.
* `edit.select_all` takes every visible, unlocked layer's artwork at the playhead (the camera
and armature layers only while active: one holds the camera, the other's instances are posed
by their bones). In a document with one layer nothing changes; with several, Select All now
@@ -91,6 +94,10 @@ nothing was copied.
layers, so masks and overlaps would change how the symbol looks).
7. **In the editor.**
* Interface text goes through `tr!`/`trn!` (ADR 0040). "6 elements on 4 layers" has two
counts but a template holds one plural: the layers' phrase is its own plural with its
preposition ("on {n} layers"), placed by the outer one ("{n} elements {on_layers}"), so each
language can inflect both and order them.
* Every timeline row whose layer holds selected items shows a small square in the layer's
colour after its name, as in Animate, and screen readers hear "has selected artwork".
* Properties lists the selection from every layer and titles it "6 elements on 4 layers". For
@@ -126,6 +133,4 @@ nothing was copied.
* Paste in Place across scenes keeping layers by name only (it uses the active layer and the
ones below);
* the plug-in `elements` view of other layers (it shows the active layer, as before);
* "mixed" for every Properties row (filters, blending and looping show the first instance's);
* clicking a layer name to select everything on it (Animate does; here it makes the layer
active and clears the selection, as before).
* "mixed" for every Properties row (filters, blending and looping show the first instance's).
+3 -3
View File
@@ -92,9 +92,9 @@ Next, in order:
parts cut and re-merged per layer); move, delete, duplicate, arrange, transforms, colour
effects, filters and break apart act on each layer; align, distribute, Free Transform and
copy act across them; paste keeps each layer; Convert to Symbol keeps the layers inside and
lands on the topmost; the timeline marks layers with selected artwork; Properties shows
mixed values. Not yet: clicking a layer name to select its artwork, armature instances from
inactive layers in a marquee, "mixed" on every Properties row.
lands on the topmost; the timeline marks layers with selected artwork, and a click on a
layer's name selects its artwork; Properties shows mixed values. Not yet: armature
instances from inactive layers in a marquee, "mixed" on every Properties row.
* ~~**Subselection on raw drawings, and merging everywhere** (ADR 0042)~~ ✅: hollow anchors
on connected raw shapes, handles on curves, point marquee on the active layer, dragging a
segment or fill moves what is connected, arrow keys; Snap to Objects (View › Snapping, the