Spacebar: a tap previews on release, held it is the Hand tool (#227)

Spacebar started or stopped the preview on its press, so holding it to
pan the Composition panel (Space+drag already panned there) also
toggled playback. As in After Effects, plain Spacebar now runs its
shortcut when it is released, and only if no mouse button went down
while it was held and the press didn't go to a text field; key
auto-repeat toggles nothing more. Shift+Spacebar and the numpad
preview shortcuts still run on the press.

Holding Spacebar over the Timeline's ruler and time graph is the Hand
tool there too: dragging scrolls the time graph (when zoomed in, never
before the comp's start or past its end) instead of moving bars, keys
or markers.

Test: spacebar_taps_preview_and_held_spacebar_pans_the_viewer,
spacebar_drag_scrolls_the_time_graph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-08 12:59:40 +07:00
co-authored by Claude Opus 5.5
parent e1062ab81b
commit e008085a93
6 changed files with 152 additions and 7 deletions
+37
View File
@@ -124,3 +124,40 @@ fn semicolon_toggles_frame_level_and_the_whole_comp() {
effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "timeline.zoomFrameToggle", json!({})).unwrap();
assert_eq!(h.state().ui.timeline.pps, None);
}
fn space(h: &mut Harness<'_, EffectcraftApp>, pressed: bool) {
h.event(Event::Key { key: egui::Key::Space, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE });
h.step();
}
/// #227: with Spacebar held, a drag over the time graph scrolls it in time (the Hand tool)
/// instead of moving the layer bar under the pointer, and the release doesn't preview.
#[test]
fn spacebar_drag_scrolls_the_time_graph() {
let (mut h, layer) = harness();
// (Opening the comp showed all of it.)
h.state_mut().ui.timeline.pps = Some(200.0);
h.state_mut().ui.timeline.start = 10.0;
h.run_steps(2);
let in_point = |h: &Harness<'_, EffectcraftApp>| h.state().session.active_comp().unwrap().layers[0].in_point.seconds();
let from = pos2(rect(&h, "timeline.ruler").center().x, over_bar(&h, layer).y);
// 400 px to the left at 200 px/s: 2 s later.
space(&mut h, true);
drag(&mut h, from, from - vec2(400.0, 0.0));
space(&mut h, false);
let (a, _) = visible(&h);
assert!((a - 12.0).abs() < 0.01, "starts at {a}");
assert_eq!(in_point(&h), 0.0, "the bar didn't move");
assert!(!h.state().playback.playing, "a Spacebar drag doesn't preview");
// To the right, at most back to the comp's start.
space(&mut h, true);
for _ in 0..6 {
drag(&mut h, from, from + vec2(500.0, 0.0));
}
space(&mut h, false);
assert_eq!(visible(&h).0, 0.0);
assert_eq!(in_point(&h), 0.0);
// Without Spacebar the same drag moves the bar.
drag(&mut h, from, from - vec2(400.0, 0.0));
assert!(in_point(&h) < -1.0, "{}", in_point(&h));
}
+61
View File
@@ -761,6 +761,67 @@ fn middle_and_hand_drags_pan_the_viewer_and_the_pan_stays_after_release() {
assert!((end[0] - after[0] + 50.0).abs() < 1.0 && (end[1] - after[1] + 30.0).abs() < 1.0, "{after:?} → {end:?}");
}
/// A Spacebar press or release (`repeat`: the keyboard's auto-repeat while it is held).
fn space(h: &mut Harness<'_, EffectcraftApp>, pressed: bool, repeat: bool) {
h.input_mut().events.push(Event::Key { key: egui::Key::Space, physical_key: None, pressed, repeat, modifiers: Default::default() });
h.step();
}
/// #227: a Spacebar tap starts and stops the preview when it is released; held, Spacebar is the
/// Hand tool, so a drag pans the viewer and neither starts nor stops the preview. Auto-repeat
/// while it is held toggles nothing more, and a space typed in a text field doesn't preview.
#[test]
fn spacebar_taps_preview_and_held_spacebar_pans_the_viewer() {
let mut h = harness();
let playing = |h: &Harness<'_, EffectcraftApp>| h.state().playback.playing;
let tap = |h: &mut Harness<'_, EffectcraftApp>| {
space(h, true, false);
space(h, false, false);
};
space(&mut h, true, false);
assert!(!playing(&h), "the press alone doesn't play");
space(&mut h, false, false);
assert!(playing(&h), "the release does");
tap(&mut h);
assert!(!playing(&h), "another tap stops");
// Held with auto-repeat: one toggle, on the release.
space(&mut h, true, false);
for _ in 0..5 {
space(&mut h, true, true);
}
assert!(!playing(&h));
space(&mut h, false, false);
assert!(playing(&h));
tap(&mut h);
// Held and dragged: pans the viewer (the Box under the pointer stays), and plays nothing.
let box_pos = |h: &Harness<'_, EffectcraftApp>| h.state().session.active_comp().unwrap().layers[0].props.prop("transform/position").unwrap().value.clone();
let (pos, before) = (box_pos(&h), h.state().ui.viewer.pan);
let c = rect(&h, "viewer.comp").center();
space(&mut h, true, false);
drag_with(&mut h, egui::PointerButton::Primary, c, c + vec2(80.0, 40.0));
space(&mut h, false, false);
let after = h.state().ui.viewer.pan;
assert!((after[0] - before[0] - 80.0).abs() < 1.0 && (after[1] - before[1] - 40.0).abs() < 1.0, "{before:?} → {after:?}");
assert_eq!(box_pos(&h), pos);
assert!(!playing(&h), "a Spacebar drag doesn't start the preview");
// Nor stop one.
tap(&mut h);
let c = rect(&h, "viewer.comp").center();
space(&mut h, true, false);
drag_with(&mut h, egui::PointerButton::Primary, c, c - vec2(30.0, 0.0));
space(&mut h, false, false);
assert!(playing(&h), "a Spacebar drag doesn't stop the preview");
tap(&mut h);
assert!(!playing(&h));
// In a text field Spacebar types.
let search = rect(&h, "timeline.search").center();
click(&mut h, search);
tap(&mut h);
assert!(!playing(&h), "a space typed in the Timeline search doesn't preview");
}
#[test]
fn timeline_rows_drag_to_reorder_layers() {
let mut h = harness();