Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

fix(engine): Close Gapをキーで実行できるようにする (#1135)

Ikki Nishihara82c162fee654
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index 6609afddf..639e05249 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -1763,7 +1763,14 @@ fn build() -> Vec<CommandSpec> {
}
remove_transitions(s, &ids, "Clear Transition")
}),
- cmd!("sequence.closeGap", "Close Gap", ["Sequence"], None, r#"{"track":"V1"|id,"time":ticks}"#, has_seq, |s, p| {
+ cmd!("sequence.closeGap", "Close Gap", ["Sequence"], None, r#"{"track":"V1"|id?,"time":ticks?}"#, has_seq, |s, p| {
+ // Shortcuts and menus have no parameters. Resolve that form from the selected gap
+ // (#1135); explicit requests keep their existing track/time validation.
+ if p.as_object().is_some_and(|p| p.is_empty()) {
+ let gap = s.state.gap_selection.ok_or_else(|| bad("sequence.closeGap", "select a gap or provide `track`"))?;
+ ripple_delete_gap(s, gap)?;
+ return Ok(Value::Null);
+ }
let tr = track_p(s, p, "track", "sequence.closeGap")?.ok_or_else(|| bad("sequence.closeGap", "need `track`"))?;
let t = time_p(s, p, "").unwrap_or(s.playhead());
close_gap(s, tr, t)?;
diff --git a/crates/engine/src/gap_selection_tests.rs b/crates/engine/src/gap_selection_tests.rs
index 66f1d2d95..19abd7c4c 100644
--- a/crates/engine/src/gap_selection_tests.rs
+++ b/crates/engine/src/gap_selection_tests.rs
@@ -172,3 +172,63 @@ fn the_gap_selection_is_part_of_the_ui_state() {
let back: crate::EditorState = serde_json::from_value(v).unwrap();
assert_eq!(back.gap_selection, s.state.gap_selection);
}
+
+#[test]
+fn close_gap_is_available_for_custom_shortcuts() {
+ let mut s = Session::default();
+ let rows = s.execute("shortcuts.list", json!({"query":"Close Gap"})).unwrap();
+ assert_eq!(rows.as_array().unwrap().len(), 1);
+ assert_eq!(rows[0]["id"], "sequence.closeGap");
+ assert!(rows[0]["shortcuts"].as_array().unwrap().is_empty(), "no new default binding");
+ s.execute("shortcuts.set", json!({"command":"sequence.closeGap","keys":"Alt+Shift+F8"})).unwrap();
+ assert_eq!(s.shortcuts.primary("sequence.closeGap").as_deref(), Some("Alt+Shift+F8"));
+}
+
+#[test]
+fn close_gap_without_params_closes_selected_gap_in_one_undo_step() {
+ let mut s = Session::default();
+ let [(first, _), (second, sound)] = two_clips(&mut s, [0, 96]);
+ let frame = s.sequence_rate().tick_of(48);
+ s.execute("timeline.selectGap", json!({"track":"V1","frame":60})).unwrap();
+ let before = serde_json::to_value(&s.project).unwrap();
+ let undo = s.history.undo.len();
+ assert_eq!(s.execute("sequence.closeGap", json!({})).unwrap(), serde_json::Value::Null);
+ assert_eq!(range(&s, first).0, Tick::ZERO);
+ assert_eq!(range(&s, second).0, frame);
+ assert_eq!(range(&s, sound).0, frame);
+ assert!(s.state.gap_selection.is_none());
+ assert_eq!(s.history.undo.len(), undo + 1);
+ let after = serde_json::to_value(&s.project).unwrap();
+ s.undo();
+ assert_eq!(serde_json::to_value(&s.project).unwrap(), before);
+ s.redo();
+ assert_eq!(serde_json::to_value(&s.project).unwrap(), after);
+}
+
+#[test]
+fn close_gap_rejects_invalid_context_and_explicit_parameters_without_editing() {
+ let mut s = Session::default();
+ two_clips(&mut s, [0, 96]);
+ let before = s.project.clone();
+ let undo = s.history.undo.len();
+ assert!(s.execute("sequence.closeGap", json!({})).is_err(), "a shortcut needs a selected gap");
+ s.execute("timeline.selectGap", json!({"track":"V1","frame":60})).unwrap();
+ for params in [json!({"track":null}), json!({"track":false}), json!({"track":"V99","frame":60}), json!({"time":1})] {
+ assert!(s.execute("sequence.closeGap", params).is_err(), "invalid explicit requests must not fall back to the selected gap");
+ assert!(std::sync::Arc::ptr_eq(&before, &s.project));
+ assert_eq!(s.history.undo.len(), undo);
+ }
+ let selected = s.state.gap_selection.unwrap();
+ s.state.gap_selection.as_mut().unwrap().range.duration += Tick(1);
+ assert!(s.execute("sequence.closeGap", json!({})).is_err(), "a stale span cannot close a different gap");
+ assert!(s.state.gap_selection.is_none());
+ assert!(std::sync::Arc::ptr_eq(&before, &s.project));
+ assert_eq!(s.history.undo.len(), undo);
+ s.execute("timeline.setTrack", json!({"track":"V1","locked":true})).unwrap();
+ s.state.gap_selection = Some(selected);
+ let before = s.project.clone();
+ let undo = s.history.undo.len();
+ assert!(s.execute("sequence.closeGap", json!({})).is_err(), "locking a selected gap must protect both picture and sound");
+ assert!(std::sync::Arc::ptr_eq(&before, &s.project));
+ assert_eq!(s.history.undo.len(), undo);
+}
diff --git a/crates/ui-egui/tests/timeline_gap_ui.rs b/crates/ui-egui/tests/timeline_gap_ui.rs
index 930f291dc..e12938244 100644
--- a/crates/ui-egui/tests/timeline_gap_ui.rs
+++ b/crates/ui-egui/tests/timeline_gap_ui.rs
@@ -33,12 +33,23 @@ impl Driver {
let (a, b) = (v1.items[0].id, v1.items[1].id);
let (tx, rx) = channel();
let app = FilmcraftApp::new(s).with_control(rx);
- let harness = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_max_steps(10_000).build_eframe(move |_cc| app);
+ let mut builder = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_max_steps(10_000);
+ if std::env::var_os("FILMCRAFT_UI_SHOTS").is_some() {
+ builder = builder.wgpu();
+ }
+ let harness = builder.build_eframe(move |_cc| app);
let mut d = Driver { harness, tx };
d.frames(4);
(d, a, b)
}
+ fn shot(&mut self, name: &str) {
+ let Some(dir) = std::env::var_os("FILMCRAFT_UI_SHOTS").map(std::path::PathBuf::from) else { return };
+ self.frames(3);
+ std::fs::create_dir_all(&dir).unwrap();
+ self.harness.render().unwrap().save(dir.join(format!("{name}.png"))).unwrap();
+ }
+
fn frames(&mut self, n: usize) {
for _ in 0..n {
// the control channel's clicks and keys enter through the input hook
@@ -165,3 +176,38 @@ fn the_gap_menu_follows_an_edit_point_menu() {
assert!(d.rect("timeline.gapMenu.edit.rippleDelete").is_some(), "the gap's menu");
assert!(d.rect("timeline.editPointMenu.rippleIn").is_none(), "not the edit point menu");
}
+
+#[test]
+fn close_gap_can_be_found_assigned_and_run_from_the_shortcut_editor() {
+ let (mut d, a, b) = Driver::two_clips();
+ let before = serde_json::to_value(&d.harness.state().session.project).unwrap();
+ d.ok("ui.menu.invoke", json!({"id":"app.keyboardShortcuts"}));
+ d.frames(4);
+ d.ok("ui.click", json!({"id":"shortcuts.search"}));
+ d.ok("ui.type", json!({"text":"Close Gap"}));
+ d.frames(2);
+ assert_eq!(d.harness.state().shortcut_editor.search, "Close Gap");
+ assert!(d.rect("shortcuts.row.sequence.closeGap").is_some(), "Close Gap must be searchable and assignable");
+ d.shot("close-gap-shortcut-found");
+ d.ok("ui.click", json!({"id":"shortcuts.cell.sequence.closeGap"}));
+ d.frames(3);
+ d.shot("close-gap-shortcut-recording");
+ assert_eq!(d.harness.state().shortcut_editor.recording, Some(("sequence.closeGap".into(), false)), "{:?}", d.harness.state().shortcut_editor);
+ d.ok("ui.key", json!({"key":"Alt+Shift+F8"}));
+ d.frames(3);
+ assert_eq!(d.harness.state().session.shortcuts.primary("sequence.closeGap").as_deref(), Some("Alt+Shift+F8"));
+ d.shot("close-gap-shortcut-assigned");
+ d.ok("ui.click", json!({"id":"shortcuts.ok"}));
+ d.click_between(a, b, "left");
+ assert_eq!(serde_json::to_value(&d.harness.state().session.project).unwrap(), before, "shortcut editing and gap selection do not edit the project");
+ let undo = d.harness.state().session.history.undo.len();
+ d.ok("ui.key", json!({"key":"Alt+Shift+F8"}));
+ d.frames(3);
+ assert_eq!(d.start(b), d.frame(48));
+ assert_eq!(d.start(a), 0);
+ assert_eq!(d.gap(), Value::Null);
+ assert_eq!(d.harness.state().session.history.undo.len(), undo + 1);
+ d.shot("close-gap-shortcut-result");
+ d.ok("engine.execute", json!({"command":"edit.undo","params":{}}));
+ assert_eq!(serde_json::to_value(&d.harness.state().session.project).unwrap(), before);
+}