FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Merge main into #608 (effect_controls drag stop, tests)
Brandon Thomas95302ee2a53c
diff --cc crates/engine/src/tests.rsindex e3905d6b2,f6fbec601..c95b5ac0c--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@@ -959,46 -1012,33 +1012,77 @@@ fn enable_flips_each_selected_clip()assert_eq!((enabled(&s, a), enabled(&s, b)), (true, true));}+/// #580: Escape takes back what a gesture changed, merged or not: the project returns to the mark,+/// neither undo nor redo keeps the changes, and older steps stay.+#[test]+fn reverting_to_a_mark_takes_back_a_gesture_without_redo() {+ let mut s = demo_unlocked();+ let id = v1(&s)[0].0;+ let opacity = |s: &Session| {+ let q = s.active_sequence().unwrap();+ let it = q.find_item(ClipId(id)).unwrap().1;+ it.effects.iter().find(|e| e.effect == "opacity").unwrap().params["opacity"].value.as_f64().unwrap()+ };+ let set = |s: &mut Session, v: f64, merge: bool, begin: bool| {+ s.execute("effects.setParam", json!({"clip": id, "effect": "opacity", "param": "opacity", "value": v, "merge": merge, "begin": begin})).unwrap();+ };+ set(&mut s, 80.0, false, false); // an earlier edit, kept+ let (start, undo, mark) = (opacity(&s), s.history.undo.len(), s.undo_mark());+ set(&mut s, 90.0, true, true); // a merged drag…+ set(&mut s, 70.0, true, false);+ set(&mut s, 60.0, false, false); // …and changes made one step each+ set(&mut s, 50.0, false, false);+ assert_eq!(s.revert_to(mark), 3);+ assert_eq!(opacity(&s), start, "the value at the mark");+ assert_eq!(s.history.undo.len(), undo, "the earlier step stays");+ assert!(s.history.redo.is_empty(), "nothing to redo");+ assert_eq!(s.revert_to(mark), 0, "nothing left to take back");+ s.undo();+ assert_eq!(opacity(&s), 100.0, "undo still takes back the earlier edit");+}++/// A mark no longer in the history does nothing; an older mark still takes back what followed it.+#[test]+fn reverting_to_a_lost_mark_does_nothing() {+ let mut s = demo_unlocked();+ let id = v1(&s)[0].0;+ let (base, start) = (s.history.undo.len(), s.undo_mark());+ s.execute("effects.setParam", json!({"clip": id, "effect": "opacity", "param": "opacity", "value": 40.0})).unwrap();+ let mark = s.undo_mark();+ s.undo();+ s.execute("effects.setParam", json!({"clip": id, "effect": "opacity", "param": "opacity", "value": 30.0})).unwrap();+ assert_eq!(s.revert_to(mark), 0, "the marked step was undone and replaced");+ assert_eq!(s.revert_to(start), 1);+ assert_eq!(s.history.undo.len(), base);+}+++ /// Times before sequence start are unreachable in the GUI and cut off on export.+ #[test]+ fn negative_place_and_marker_times_are_refused() {+ let mut s = demo();+ let item = s.active_sequence().unwrap().video_tracks[0].items[0].item;+ let before = s.project.clone();+ let n_markers = s.active_sequence().unwrap().markers.len();+ let n_clips: usize = s.active_sequence().unwrap().video_tracks.iter().map(|t| t.items.len()).sum();+ for (cmd, params) in [+ ("timeline.place", json!({"item": item.0, "frame": -12})),+ ("timeline.place", json!({"item": item.0, "seconds": -1.0})),+ ("timeline.place", json!({"item": item.0, "time": -1})),+ ("markers.add", json!({"frame": -10})),+ ("markers.add", json!({"seconds": -0.5})),+ ("markers.add", json!({"time": i64::MIN})),+ ("markers.addChapter", json!({"frame": -1})),+ ("markers.addRange", json!({"time": -1, "durationFrames": 10})),+ ("markers.addFlashCue", json!({"frame": -3})),+ ] {+ let e = s.execute(cmd, params.clone()).expect_err(&format!("{cmd} {params}"));+ assert!(matches!(&e, EngineError::BadParams { cmd: c, msg } if c == cmd && msg.contains("negative")), "{cmd} {params}: {e:?}");+ assert_eq!(*s.project, *before);+ }+ assert_eq!(s.active_sequence().unwrap().markers.len(), n_markers);+ let n_clips_after: usize = s.active_sequence().unwrap().video_tracks.iter().map(|t| t.items.len()).sum();+ assert_eq!(n_clips_after, n_clips);+ s.execute("timeline.place", json!({"item": item.0, "frame": 0})).unwrap();+ s.execute("markers.add", json!({"frame": 0, "name": "start"})).unwrap();+ assert!(s.active_sequence().unwrap().markers.iter().any(|m| m.start == Tick::ZERO && m.name == "start"));+ }diff --cc crates/ui-egui/src/panels/effect_controls.rsindex 7c0e943c1,420cd92e8..72d676163--- a/crates/ui-egui/src/panels/effect_controls.rs+++ b/crates/ui-egui/src/panels/effect_controls.rs@@@ -963,20 -971,22 +974,22 @@@ pub fn properties_panel(app: &mut Filmcrun(app, ui.ctx(), actions);}-/// Run the panel's actions. Parameter changes made while the mouse button is down (a drag) share-/// one undo step, which the first change of each press begins (#201); typed values and clicks stay-/// separate steps. A drag value only changes once the mouse moves, after the press frame, so the-/// press that already began a step is remembered by its start time. That memory is refreshed on-/// every frame the button stays down — including frames with no value change — so a Scale scrub-/// that pauses between percents is still one undo (#887).-fn run(app: &mut FilmcraftApp, ctx: &egui::Context, actions: Vec<(String, Value)>) {+/// Run the panel's actions (also the Lumetri Color panel's). Parameter changes made+/// while the mouse button is down (a drag) share one undo step, which the first change of each+/// press begins (#201); typed values and clicks stay separate steps. A drag value only changes once+/// the mouse moves, after the press frame, so the press that already began a step is remembered by- /// its start time.++/// its start time. That memory is refreshed on every frame the button stays down — including frames++/// with no value change — so a Scale scrub that pauses between percents is still one undo (#887).+pub(crate) fn run(app: &mut FilmcraftApp, ctx: &egui::Context, actions: Vec<(String, Value)>) {let (down, press) = ctx.input(|i| (i.pointer.any_down(), i.pointer.press_start_time()));let key = egui::Id::new("effect-controls-drag-step");+ let begun = ctx.data(|d| d.get_temp::<Option<f64>>(key)).flatten();+ let mut wrote = false;for (cmd, mut p) in actions {if cmd == "effects.setParam" && down {- let begun = ctx.data(|d| d.get_temp::<Option<f64>>(key)).flatten();p["merge"] = json!(true);p["begin"] = json!(begun != press);- ctx.data_mut(|d| d.insert_temp(key, press));+ wrote = true;}if let Err(e) = app.session.execute(&cmd, p) {app.ui.status = e.to_string();@@@ -1146,9 -1164,7 +1167,9 @@@ pub(crate) fn graph_rowslet nx = graph_drag_offset(ui, &hr, vec2(hdx, 0.0)).x;ui.data_mut(|d| d.insert_temp(hid, nx));}- if hr.drag_stopped_by(egui::PointerButton::Primary) {+ if hr.drag_stopped() && ui.input(|i| i.key_pressed(egui::Key::Escape)) {+ ui.data_mut(|d| d.remove::<f32>(hid));- } else if hr.drag_stopped() {++ } else if hr.drag_stopped_by(egui::PointerButton::Primary) {ui.data_mut(|d| d.remove::<f32>(hid));let ni = ((infl * seg + hdx * side) / seg.max(1.0)).clamp(0.01, 1.0);let key = if side > 0.0 { "outInfluence" } else { "inInfluence" };@@@ -1164,10 -1180,7 +1185,10 @@@ui.data_mut(|d| d.insert_temp(id, ny));p.text(c + vec2(8.0, -10.0), Align2::LEFT_BOTTOM, format!("{:.dec$}", v_of(c.y)), Tokens::ui(10.5), t.hot_text);}- if resp.drag_stopped_by(egui::PointerButton::Primary) {+ // egui ends a drag on Escape: that stop abandons it (#580)+ if resp.drag_stopped() && ui.input(|i| i.key_pressed(egui::Key::Escape)) {+ ui.data_mut(|d| d.remove::<f32>(id));- } else if resp.drag_stopped() {++ } else if resp.drag_stopped_by(egui::PointerButton::Primary) {ui.data_mut(|d| d.remove::<f32>(id));let nv = v_of(c.y);let nv = if let ParamKind::Float { min, max, .. } = pd.kind { nv.clamp(min, max) } else { nv };