From a55ca843e8fe2215112b60426f194f5f5fb49213 Mon Sep 17 00:00:00 2001 From: jayzed80 Date: Thu, 12 Nov 2026 10:31:10 +0000 Subject: [PATCH 1/2] fix(timeline): a click on the playhead selects its frame on every layer, so F5 and the other frame keys act on all layers Clicking or dragging the frame ruler only moved the playhead and left the frame selection on one layer, so Insert Frame (F5), Remove Frames, the keyframe keys and Copy/Cut Frames went to the active layer only. The ruler now selects the playhead's frame from the first to the last layer; clicking a frame of one layer narrows it to that layer again. Each command stays one undo step. Fixes #195 --- docs/guide/timeline.md | 2 ++ src/timeline.rs | 67 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/docs/guide/timeline.md b/docs/guide/timeline.md index 2667634f..a06a9ed8 100644 --- a/docs/guide/timeline.md +++ b/docs/guide/timeline.md @@ -120,6 +120,8 @@ An empty frame shows a hint in **Properties › Frame**: press **F7** to start d * Click a frame to select it and move the playhead there. * **Shift**-click, or drag across frames, to select a range. A selection can span several layers. +* Click the playhead (the frame ruler) to select that frame on every layer. **F5**, **F6** + and the other frame keys then act on all layers, until you click a frame of one layer. * **Ctrl+Alt+A** selects every frame. The frame keys, the header buttons and the right-click menu all act on the whole selection. diff --git a/src/timeline.rs b/src/timeline.rs index adf0b28d..625989a9 100644 --- a/src/timeline.rs +++ b/src/timeline.rs @@ -403,6 +403,12 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { && let Some(p) = ruler_resp.interact_pointer_pos() { app.playing = false; app.run("timeline.goto", json!({"frame": frame_at(p.x)})); + // The playhead's frame on every layer, as in Animate: F5, F6, Shift+F5 and the + // other frame commands then act on all layers until a frame of one layer is clicked. + let layers = &app.s.timeline().layers; + if let (Some(a), Some(b)) = (layers.first(), layers.last()) { + app.frame_sel = Some(FrameSel { anchor: (a.id, app.s.frame), head: (b.id, app.s.frame) }); + } } // The onion menu on a right-click, as the markers live here (ADR 0047). ruler_resp.context_menu(|ui| crate::onion::menu(app, ui)); @@ -1659,4 +1665,65 @@ mod tests { // A deleted layer invalidates the selection. assert!(FrameSel { anchor: (LayerId(9), 0), head: (LayerId(1), 0) }.layers(&ls).is_empty()); } + + /// Each layer's length, in frames. + fn ends(app: &App) -> Vec<(LayerId, u32)> { + app.s.timeline().layers.iter().map(|l| (l.id, l.end_frame())).collect() + } + + /// Issue 195: a click on the playhead (the frame ruler) picks that frame on every layer, so + /// F5 adds a frame to all of them; a click on one layer's frame goes back to that layer. + #[test] + fn a_click_on_the_playhead_makes_frame_keys_act_on_every_layer() { + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + let mut app = App::with_context(&ctx, anicraft_engine::Session::new(anicraft_engine::doc::sample::demo()), Some(std::path::PathBuf::from("unused.png"))); + let screen = Rect::from_min_size(egui::Pos2::ZERO, vec2(1600.0, 940.0) / app.prefs.ui_scale); + let frame = |app: &mut App, events: Vec| { + let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| app.frame(ui)); + out.textures_delta.clear(); + out.platform_output.accesskit_update + }; + let mut tree = None; + for _ in 0..3 { + tree = frame(&mut app, Vec::new()).or(tree); + } + let layers: Vec = app.s.timeline().layers.iter().filter(|l| l.kind != LayerKind::Folder).map(|l| l.id).collect(); + assert!(layers.len() >= 2, "the sample has several layers: {layers:?}"); + // The second layer is the active one, as after a click on its name. + app.s.layer = layers[1]; + // The frame ruler, found by its name for screen readers. + let ppp = ctx.pixels_per_point(); + let ruler = tree + .and_then(|t| t.nodes.into_iter().find(|(_, n)| n.label() == Some("Playhead (frame ruler)"))) + .and_then(|(_, n)| n.bounds()) + .map(|b| Rect::from_min_max(pos2(b.x0 as f32, b.y0 as f32) / ppp, pos2(b.x1 as f32, b.y1 as f32) / ppp)) + .unwrap_or_else(|| panic!("no frame ruler on screen")); + // Click the ruler a little way in (frame 3 or so). + let at = pos2(ruler.left() + 40.0, ruler.center().y); + let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + frame(&mut app, vec![egui::Event::PointerMoved(at)]); + frame(&mut app, vec![press(true)]); + frame(&mut app, vec![press(false)]); + frame(&mut app, Vec::new()); + let f = app.s.frame; + assert!(f > 0, "the click moved the playhead"); + let before = ends(&app); + let steps = app.s.history_len(); + app.invoke("timeline.insert_frame"); + assert_eq!(app.s.history_len(), steps + 1, "one undo step"); + // The same as F5 on every layer at the playhead. + let all = ends(&app); + app.s.undo().expect("undo"); + assert_eq!(ends(&app), before, "one undo takes it all back"); + app.run("timeline.insert_frame", json!({"layers": layers.iter().map(|l| l.0).collect::>(), "frame": f})); + assert_eq!(all, ends(&app), "F5 after a click on the playhead adds a frame on every layer"); + app.s.undo().expect("undo"); + assert!(before.iter().zip(&all).filter(|(b, a)| b != a).count() >= 2, "more than one layer grew: {before:?} → {all:?}"); + // A click on one layer's frame (what the grid does) acts on that layer only again. + app.frame_sel = Some(FrameSel::cell(layers[1], f)); + app.invoke("timeline.insert_frame"); + let one = ends(&app); + assert_eq!(before.iter().zip(&one).filter(|(b, a)| b != a).map(|(b, _)| b.0).collect::>(), vec![layers[1]]); + } } From 8b99dc49fe6fe526a79b1d153968a4cfff9604c4 Mon Sep 17 00:00:00 2001 From: jayzed80 Date: Thu, 19 Nov 2026 20:12:56 +0000 Subject: [PATCH 2/2] fix(timeline): a click on the ruler focuses the timeline so Ctrl+X/C/V act on frames The ruler selected the playhead's frame on every layer but left timeline_focus alone, so after a stage click Ctrl+C/X/V still went to artwork. Set the flag as a click on a frame does, and cover the routing in the ruler test. The guide's no-selection example no longer uses scrubbing, which now selects frames. --- docs/guide/timeline.md | 8 ++++---- src/timeline.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/guide/timeline.md b/docs/guide/timeline.md index 1c767017..6b38349e 100644 --- a/docs/guide/timeline.md +++ b/docs/guide/timeline.md @@ -200,10 +200,10 @@ As in Animate, the keys keep you moving along the timeline: * **F6** or **F7** on a frame that is already a keyframe adds the new keyframe on the *next* frame and moves there, so you can draw, press **F6**, draw again, and so on. On any other frame they key the frame you're on. -* With no frames selected (for example after scrubbing the playhead), **F5** adds a frame on - every layer that has frames at or after the playhead, so the layers stay in step. Layers that - end before the playhead are left alone. When no layer reaches the playhead, it lengthens the - layer you're on up to it. +* With no frames selected (for example after stepping the playhead out of the selection), + **F5** adds a frame on every layer that has frames at or after the playhead, so the layers + stay in step. Layers that end before the playhead are left alone. When no layer reaches the + playhead, it lengthens the layer you're on up to it. * With a frame selected, the keys act on that frame's layer, and the selection moves with the playhead. * With several frames selected, **F6** makes every one of them a keyframe of what it showed, and diff --git a/src/timeline.rs b/src/timeline.rs index 664d5eb3..516933f7 100644 --- a/src/timeline.rs +++ b/src/timeline.rs @@ -666,6 +666,9 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) { if let (Some(a), Some(b)) = (layers.first(), layers.last()) { app.frame_sel = Some(FrameSel { anchor: (a.id, app.s.frame), head: (b.id, app.s.frame) }); } + // Keyboard focus follows the click, as it does on a frame: Ctrl+X/C/V then act on + // the selected frames, not on artwork. + app.timeline_focus = true; } // The onion menu on a right-click, as the markers live here (ADR 0047). ruler_resp.context_menu(|ui| crate::onion::menu(app, ui)); @@ -2243,6 +2246,11 @@ mod tests { frame(&mut app, vec![press(true)]); frame(&mut app, vec![press(false)]); frame(&mut app, Vec::new()); + // The click takes the keyboard focus to the timeline, as a click on a frame does, so + // Ctrl+C copies the selected frames rather than artwork. + assert!(app.timeline_focus, "a click on the ruler focuses the timeline"); + app.invoke("edit.copy"); + assert!(!app.s.frame_clipboard.is_empty(), "Ctrl+C after a click on the ruler copies frames"); let f = app.s.frame; assert!(f > 0, "the click moved the playhead"); let before = ends(&app);