From 23d322163d70eb9660c6598cb2daaae9bd5bee67 Mon Sep 17 00:00:00 2001 From: "Ayberk A." <105879357+AyberkA0@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:30:49 +0300 Subject: [PATCH] fix(timeline): Next and Previous Frame stop at the ends (#561) "." on the last frame went round to the first, and "," on the first to the last. They now stay there, as the timeline's arrow keys already did, and Next no longer pulls a playhead that is past the last frame back. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmds_timeline.rs | 11 +++++++---- crates/engine/src/timeline_key_tests.rs | 18 ++++++++++++++++++ docs/guide/reference/commands.md | 4 ++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmds_timeline.rs b/crates/engine/src/cmds_timeline.rs index 7e9191f5..36ecf924 100644 --- a/crates/engine/src/cmds_timeline.rs +++ b/crates/engine/src/cmds_timeline.rs @@ -33,8 +33,8 @@ pub fn specs() -> Vec { ), c("timeline.set_label", "Frame Label", "", None, "{label, layer?, frame?}", true, set_label), c("timeline.goto", "Go to Frame", "", None, "{frame}", false, goto), - c("timeline.next_frame", "Next Frame", "Control", Some("."), "{}", false, |s, _| step(s, 1)), - c("timeline.prev_frame", "Previous Frame", "Control", Some(","), "{}", false, |s, _| step(s, -1)), + c("timeline.next_frame", "Next Frame", "Control", Some("."), "{} (on the last frame it stays there)", false, |s, _| step(s, 1)), + c("timeline.prev_frame", "Previous Frame", "Control", Some(","), "{} (on the first frame it stays there)", false, |s, _| step(s, -1)), c("timeline.first_frame", "Go to First Frame", "Control", Some("Home"), "{}", false, |s, _| { s.set_frame(0); Ok(json!({"frame": 0})) @@ -816,9 +816,12 @@ fn goto(s: &mut Session, p: &Value) -> Result { Ok(json!({"frame": s.frame})) } +/// One frame on or back, stopping at the first and the last frame rather than going round +/// (#561), as the arrow keys in the timeline do. fn step(s: &mut Session, d: i64) -> Result { - let n = i64::from(s.frame_count().max(1)); - let f = (i64::from(s.frame) + d).rem_euclid(n); + let (now, last) = (i64::from(s.frame), i64::from(s.frame_count().max(1)) - 1); + // A playhead already past the last frame (on an empty cell) isn't pulled back by Next. + let f = (now + d).clamp(0, last.max(now)); s.set_frame(f as u32); Ok(json!({"frame": s.frame})) } diff --git a/crates/engine/src/timeline_key_tests.rs b/crates/engine/src/timeline_key_tests.rs index 58bf50bc..0d9114af 100644 --- a/crates/engine/src/timeline_key_tests.rs +++ b/crates/engine/src/timeline_key_tests.rs @@ -173,3 +173,21 @@ fn advance_at_the_last_frame_stays_in_range() { let _ = s.execute("timeline.insert_keyframe", &json!({"advance": true})); assert!(s.frame <= MAX_FRAME); } + +/// #561: Next and Previous Frame (`.` and `,`) stop at the last and the first frame instead of +/// going round to the other end. +#[test] +fn stepping_stops_at_the_ends() { + let mut s = Session::default(); + let l = s.layer; + run(&mut s, "timeline.insert_frame", json!({"layer": l.0, "frame": 0, "count": 4})); + let last = s.frame_count() - 1; + run(&mut s, "timeline.goto", json!({"frame": last})); + run(&mut s, "timeline.next_frame", json!({})); + assert_eq!(s.frame, last, "the last frame stays"); + run(&mut s, "timeline.goto", json!({"frame": 0})); + run(&mut s, "timeline.prev_frame", json!({})); + assert_eq!(s.frame, 0, "the first frame stays"); + run(&mut s, "timeline.next_frame", json!({})); + assert_eq!(s.frame, 1, "in between, one frame on"); +} diff --git a/docs/guide/reference/commands.md b/docs/guide/reference/commands.md index 3068d543..1431d722 100644 --- a/docs/guide/reference/commands.md +++ b/docs/guide/reference/commands.md @@ -289,9 +289,9 @@ This page is generated from the command registry, so it always matches the versi ## Control - **Next Frame** `timeline.next_frame` · **.** - Parameters: `{}` + Parameters: `{} (on the last frame it stays there)` - **Previous Frame** `timeline.prev_frame` · **,** - Parameters: `{}` + Parameters: `{} (on the first frame it stays there)` - **Go to First Frame** `timeline.first_frame` · **Home** Parameters: `{}` - **Go to Last Frame** `timeline.last_frame` · **End**