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 <noreply@anthropic.com>
This commit is contained in:
Ayberk A.andClaude Opus 5.5 committed 2026-11-23 13:30:49 +03:00
1 parent 2df7775907
commit 23d322163d
3 files changed
+27 -6

No files matched your search

+7 -4
View File
@@ -33,8 +33,8 @@ pub fn specs() -> Vec<CommandSpec> {
),
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<Value> {
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<Value> {
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}))
}
+18
View File
@@ -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");
}
+2 -2
View File
@@ -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**