diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 8f2ad31..4c9fea9 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -36,6 +36,12 @@ impl Player { // costs nothing a real edit would not have earned anyway, and one list // here is the whole answer instead of fifteen scattered calls. // + // The two exceptions are the history pair, whose doors answer "there was + // a step to take" and are gated in their own arms below: `^z` with + // nothing to undo is not a stroke that earned an autosave, and the + // save-on-close question over a project nobody has touched is exactly + // what the card doors' own gate exists to prevent. + // // This list is the *action* doors only, and that is the class to mind // when adding an edit: a control that reaches the session from a // *click* -- the Clip tab's look chips and wheel, the settings rows, @@ -54,8 +60,6 @@ impl Player { | ActionId::Group | ActionId::Delete | ActionId::Lift - | ActionId::Undo - | ActionId::Redo | ActionId::AddVideoLane | ActionId::RemoveVideoLane | ActionId::AddAudioLane @@ -130,8 +134,16 @@ impl Player { ActionId::ZoomIn => self.zoom(ZOOM_STEP, None, cx), ActionId::ZoomOut => self.zoom(1. / ZOOM_STEP, None, cx), ActionId::ZoomFit => self.zoom_fit(cx), - ActionId::Undo => self.undo(cx), - ActionId::Redo => self.redo(cx), + ActionId::Undo => { + if self.undo(cx) { + self.mark_dirty(); + } + } + ActionId::Redo => { + if self.redo(cx) { + self.mark_dirty(); + } + } ActionId::AddVideoLane => self.add_lane(LaneKind::Video, cx), ActionId::AddAudioLane => self.add_lane(LaneKind::Audio, cx), // The last track of that kind: the one the add key put there, so the @@ -611,12 +623,17 @@ impl Player { return; }; let to = nudge_edge(current, dir, lo, hi); - self.mark_dirty(); let trimmed = self .session .as_mut() .is_some_and(|s| s.trim_clip(lane, idx, edge, to)); if trimmed { + // The arm rides the door's own answer: `trim_clip` is `false` for an + // edge already where it was asked to go -- the `[`/`]` pressed + // against the wall the edge is already on -- so the flag, the + // autosave sidecar and the save-on-close question stay off a + // project nobody has changed. + self.mark_dirty(); self.reset_after_reseek(); // Loop-trim follows the edge it is trimming: the whole point of // the mode is hearing the cut as it moves. @@ -643,12 +660,15 @@ impl Player { return; }; let to = frame_at(session.now(), self.fps); - self.mark_dirty(); let trimmed = self .session .as_mut() .is_some_and(|s| s.trim_clip(lane, idx, edge, to)); if trimmed { + // The door's own answer again: an edge the playhead is already on is + // `false`, no undo step, and nothing for the unsaved ghost to be + // about. + self.mark_dirty(); self.reset_after_reseek(); // Loop-trim follows the edge it is trimming, same as the nudge // pair above. @@ -684,20 +704,31 @@ impl Player { cx.notify(); } - pub(crate) fn undo(&mut self, cx: &mut Context) { - if self.session.as_mut().is_some_and(PlaybackSession::undo) { + /// Whether there was a step to take, for the reason the action table arms + /// nothing on its own: a `^z` with an empty history is not an edit, and it + /// may not raise the save-on-close question over a project nobody has + /// touched. The selection goes with the step for the same reason it used to + /// go every time: a step back puts the indices on different clips, while a + /// refused one leaves them naming exactly what they named. + pub(crate) fn undo(&mut self, cx: &mut Context) -> bool { + let stepped = self.session.as_mut().is_some_and(PlaybackSession::undo); + if stepped { self.reset_after_reseek(); + self.selected.clear(); } - self.selected.clear(); cx.notify(); + stepped } - pub(crate) fn redo(&mut self, cx: &mut Context) { - if self.session.as_mut().is_some_and(PlaybackSession::redo) { + /// [`Player::undo`]'s twin, the same answer and the same gate. + pub(crate) fn redo(&mut self, cx: &mut Context) -> bool { + let stepped = self.session.as_mut().is_some_and(PlaybackSession::redo); + if stepped { self.reset_after_reseek(); + self.selected.clear(); } - self.selected.clear(); cx.notify(); + stepped } } diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index cdf19b9..3f22151 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -350,7 +350,6 @@ impl Player { if self.exporting().is_some() { return; } - self.mark_dirty(); let (Some((start, _)), Some(was)) = ( self.drop_frame(from, idx, x), self.session @@ -385,6 +384,14 @@ impl Player { }; match moved { true => { + // The arm rides the door's own answer: `move_clip_to` / + // `move_selection_to` answer `false` for a clip let go where it + // was picked up (`Project::move_selection` refuses before its + // snapshot) and for a lane of the wrong kind, and the arms below + // say both in words. Armed before the call it dirtied a project + // nobody had touched -- the ledger's `unsaved` ghost and the + // save-on-close question over an unchanged file. + self.mark_dirty(); // Every pick named a `(lane, ...)` by index into that lane's // clips, sorted by start -- exactly what an insert or a lane // change reorders. Re-read by the frame each pick's clip now @@ -512,7 +519,6 @@ impl Player { if self.exporting().is_some() { return; } - self.mark_dirty(); self.snap_cue = None; self.ghost.clear(); let at = self.place_frame(x).0; @@ -533,6 +539,15 @@ impl Player { (None, Some(_)) => Some("NOT PLACED — that subtitle track has no cues".to_string()), (_, None) => Some("NOT PLACED — no file open".to_string()), }; + // The arm rides the door's own answer: `text` is `None` exactly when + // `Project::place_sub` took the track, and every refusal -- an overlap, + // a lane that is not a subtitle lane, "no file open", "no cues" -- + // leaves the project byte-for-byte what it was. Armed ahead of the + // answer it wrote an autosave sidecar, the ledger's `unsaved` ghost and + // the save-on-close question over a project nobody had changed. + if text.is_none() { + self.mark_dirty(); + } match (text, marked) { (Some(text), _) => self.notify_user(text.into()), // It went down, and a lane holds its captions in start order @@ -597,12 +612,19 @@ impl Player { if self.exporting().is_some() { return; } - self.mark_dirty(); self.snap_cue = None; self.ghost.clear(); let Some(idx) = self.dragged_sub(drag) else { return; }; + // Where the caption stands *now*, so the arm below can tell a move from + // a drag let go where it began: `Project::move_sub` answers `Ok` for a + // pick-up-put-back too ("`Ok`, and no undo step, because nothing + // changed"), so its own answer is not a change report. + let was = self + .session + .as_ref() + .and_then(|session| session.sub_lane(drag.lane).get(idx).map(|sub| sub.start)); // Asked before the edit, on the indices the press captured: the // engine's own grouped-with-clips answer, which is exactly when its // move reseeks -- a caption grouped only with other captions moves no @@ -640,6 +662,20 @@ impl Player { .as_ref() .and_then(|session| sub_mark(session.sub_lane(to), start)) .map(|i| (to, i)); + // The arm rides the caption's own place having moved -- the + // engine's `Ok` covers the put-back that takes no undo step at + // all (`Project::move_sub`), and a project nobody has touched + // must not light the `unsaved` ghost. + let landed = mark.and_then(|(lane, i)| { + self.session + .as_ref()? + .sub_lane(lane) + .get(i) + .map(|sub| (lane, sub.start)) + }); + if landed != was.map(|start| (drag.lane, start)) { + self.mark_dirty(); + } self.selected = match mark { Some(mark) => { let mut sel = Selection::new(); @@ -670,7 +706,6 @@ impl Player { if self.exporting().is_some() { return; } - self.mark_dirty(); let lifted = self .session .as_mut() @@ -683,6 +718,11 @@ impl Player { false => "NOTHING LIFTED — that caption is not there any more".to_string(), }; if lifted { + // The arm rides the door's own answer: `false` is "NOTHING LIFTED — + // that caption is not there any more", and the project is exactly + // what it was, so the flag, the autosave sidecar and the + // save-on-close question must stay off it. + self.mark_dirty(); // Everything after it on that lane slid down one ([`Vec::remove`]), // so a mark or an open menu left at or past it names a *different* // caption now -- and the next Delete would take that one. Both go @@ -1537,7 +1577,11 @@ impl Player { let Some(trim) = self.trim.take() else { return; }; - self.mark_dirty(); + // The arm rides each door's own answer or the caption's own edges -- + // never the call: a trim released where the edge already stood is + // `Ok`/`true` with no undo step, and it must not leave the project + // looking edited to autosave, the `unsaved` ghost or the close + // question. // A caption's edge reaches the engine through its own door, at this // timeline's rate. An `Ok` is *not* "something changed" -- an edge that // stopped at a wall it already stood against is `Ok` with no undo step @@ -1552,14 +1596,33 @@ impl Player { .session .as_ref() .is_some_and(|session| session.caption_grouped_with_clips(trim.lane, trim.idx)); + // The caption's own window, before and after: the only reading that + // can tell a trim from an edge released against the wall it already + // stood on. + let edges = |player: &Self| { + player.session.as_ref().and_then(|session| { + session + .sub_lane(trim.lane) + .get(trim.idx) + .map(|sub| (sub.start, sub.frames, sub.in_us, sub.out_us)) + }) + }; + let before = edges(self); let trimmed = self .session .as_mut() .map(|session| session.trim_sub(trim.lane, trim.idx, trim.edge, trim.to)); match trimmed { Some(Err(e)) => self.notify_user(format!("NOT TRIMMED — {e}").into()), - Some(Ok(())) if grouped => self.reset_after_reseek(), - _ => {} + Some(Ok(())) => { + if edges(self) != before { + self.mark_dirty(); + } + if grouped { + self.reset_after_reseek(); + } + } + None => {} } cx.notify(); return; @@ -1569,6 +1632,10 @@ impl Player { .as_mut() .is_some_and(|session| session.trim_clip(trim.lane, trim.idx, trim.edge, trim.to)); if trimmed { + // The arm rides the door's own answer: `trim_clip` is `false` for an + // edge already where it was asked to go, which is no undo step and + // no edit. + self.mark_dirty(); self.reset_after_reseek(); } cx.notify(); @@ -1643,7 +1710,20 @@ impl Player { let Some(fade) = self.fade_drag.take() else { return; }; - self.mark_dirty(); + // The ramp the clip is carrying *now*, so the arm below can tell a drag + // from a press-and-release that left the handle where it was: `set_fade_in` + // / `set_fade_out` answer `true` for any index that exists and take an + // undo step either way, so their own answer is not a change report. + let was = match fade.is_in { + true => self + .session + .as_ref() + .map(|session| session.fade_in_of(fade.lane, fade.idx)), + false => self + .session + .as_ref() + .map(|session| session.fade_out_of(fade.lane, fade.idx)), + }; let set = self .session .as_mut() @@ -1652,6 +1732,19 @@ impl Player { false => session.set_fade_out(fade.lane, fade.idx, fade.to), }); if set { + let now = match fade.is_in { + true => self + .session + .as_ref() + .map(|session| session.fade_in_of(fade.lane, fade.idx)), + false => self + .session + .as_ref() + .map(|session| session.fade_out_of(fade.lane, fade.idx)), + }; + if now != was { + self.mark_dirty(); + } cx.notify(); } } diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index e7da37e..4c9e247 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -914,7 +914,10 @@ fn the_budget_is_the_one_number_the_engine_gets() { // put on screen. assert_eq!(auto_bps(1920, 1080, 30.), 6_220_800); assert_eq!(auto_bps(160, 120, 15.), BPS_MIN, "a tiny picture floors"); - assert!(auto_bps(7680, 4320, 60.) <= 20_000_000, "and a huge one caps"); + assert!( + auto_bps(7680, 4320, 60.) <= 20_000_000, + "and a huge one caps" + ); for bps in [auto_bps(1920, 1080, 30.), auto_bps(320, 240, 24.)] { assert!((BPS_MIN..=BPS_MAX).contains(&bps)); } @@ -1067,11 +1070,25 @@ fn a_chord_the_export_moment_answers_never_reaches_the_room() { let (typing, closed) = rest .split_once("return true;") .expect("the typing branch returns before the chords below it"); - assert!(typing.contains("self.budget_edit = None"), "esc leaves the field"); - assert!(closed.contains("self.close_card()"), "then esc closes the moment"); + assert!( + typing.contains("self.budget_edit = None"), + "esc leaves the field" + ); + assert!( + closed.contains("self.close_card()"), + "then esc closes the moment" + ); // Its chords, all of them consumed here rather than by the keymap. for chord in [ - "\"d\"", "\"n\"", "\"e\"", "\"enter\"", "\"up\"", "\"down\"", "\"c\"", "\"b\"", "\"g\"", + "\"d\"", + "\"n\"", + "\"e\"", + "\"enter\"", + "\"up\"", + "\"down\"", + "\"c\"", + "\"b\"", + "\"g\"", "\",\"", ] { assert!(closed.contains(chord), "{chord} is not the moment's own"); @@ -1086,7 +1103,11 @@ fn a_chord_the_export_moment_answers_never_reaches_the_room() { fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { let cards = src_text("ui/cards.rs"); let start = cards.find("fn export_card(").expect("the moment"); - let body = &cards[start..start + cards[start..].find("\n /// ").unwrap_or(cards.len() - start)]; + let body = &cards[start + ..start + + cards[start..] + .find("\n /// ") + .unwrap_or(cards.len() - start)]; // A segment is the setter it names, not a readout of it. for (id, chord, setter) in [ ("moment-picture", "\"c\"", "cycle_export_picture"), @@ -1098,7 +1119,10 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { assert!(body.contains(setter), "the {id} segment changes nothing"); } // The door, wearing the room's own chord rather than a hand-typed one. - assert!(body.contains("moment-settings"), "row 3 has no settings door"); + assert!( + body.contains("moment-settings"), + "row 3 has no settings door" + ); assert!( body.contains("self.keymap.chord(ActionId::Settings)"), "the door's chord is not read from the keymap" @@ -1113,7 +1137,10 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { .map(|at| &cards[at..at + 1900]) .expect("the segment atom"); assert!(seg.contains("INK3()") && seg.contains("INK4()")); - assert!(seg.contains("DARK_RAISED()"), "a segment does not answer hover"); + assert!( + seg.contains("DARK_RAISED()"), + "a segment does not answer hover" + ); // The readouts worth seeing: the project's picture size and rate, and // a sound rate that is on the line whether or not it is pressable. assert!( @@ -1126,13 +1153,18 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { ); // The picture segment is a child, not a `has_video` maybe: hidden on the // sound-only formats it left `c` pressing nothing and no way back. - let at = body.find("\"moment-picture\"").expect("the picture segment"); + let at = body + .find("\"moment-picture\"") + .expect("the picture segment"); assert!( !body[at - 240..at].contains("has_video"), "the picture segment is gated on has_video again -- the dead end" ); // Wrapped, never cut: the readouts made row 3 longer than 1280 wide. - assert!(body.contains(".flex_wrap()"), "row 3 truncates instead of wrapping"); + assert!( + body.contains(".flex_wrap()"), + "row 3 truncates instead of wrapping" + ); } /// The dead end the user hit: the cycle walked into the sound-only formats @@ -1140,15 +1172,22 @@ fn row_three_wears_the_encode_options_and_the_door_to_the_rest() { /// and can't turn it back to video"). One cycle, and it wraps. #[test] fn the_picture_cycle_wraps_out_of_the_sound_only_formats() { - use crate::ui::settings_stance::{PICTURE_CYCLE, next_picture}; + use crate::ui::settings_stance::{next_picture, PICTURE_CYCLE}; // Nothing refused: every stop is the next one, and the last wraps to the // first -- OGG, the tail of the list, back to MP4. let mut at = PICTURE_CYCLE[0]; - for &want in PICTURE_CYCLE.iter().skip(1).chain(std::iter::once(&PICTURE_CYCLE[0])) { + for &want in PICTURE_CYCLE + .iter() + .skip(1) + .chain(std::iter::once(&PICTURE_CYCLE[0])) + { at = next_picture(at, |_| false); assert_eq!(at, want, "the cycle stopped walking"); } - assert_eq!(at, PICTURE_CYCLE[0], "a full walk is a wrap, not a dead end"); + assert_eq!( + at, PICTURE_CYCLE[0], + "a full walk is a wrap, not a dead end" + ); assert_eq!(next_picture(Format::Ogg, |_| false), Format::Mp4); // A timeline with no picture refuses every video format, and the cycle // still moves: the sound-only stops are what is left of it. @@ -1278,12 +1317,18 @@ fn the_moment_and_the_settings_room_wear_the_same_export_chords() { assert!(settings.contains(chord), "the EXPORT rows lost {chord}"); assert!(moment.contains(chord), "row 3 lost {chord}"); assert!(handler.contains(chord), "the moment answers no {chord}"); - assert!(player.contains(chord), "the settings page answers no {chord}"); + assert!( + player.contains(chord), + "the settings page answers no {chord}" + ); } // `e` stays the Export press: the encoder seat took `g` rather than a // shifted letter, which no ghost wears. assert!(handler.contains("\"e\" | \"enter\" => self.start_export")); - assert!(!settings.contains("\n \"e\","), "the Encoder row took `e` back"); + assert!( + !settings.contains("\n \"e\","), + "the Encoder row took `e` back" + ); } /// The Sound row: what it offers, and that the pick travels to the engine @@ -1401,9 +1446,15 @@ fn a_typed_colour_is_read_in_every_spelling_and_anything_else_is_refused() { edit.typed('z'); assert_eq!(edit.commit(), None); let why = edit.refusal.clone().expect("a refusal, not a silence"); - assert!(why.contains("#RRGGBB"), "the refusal says what a colour is: {why}"); + assert!( + why.contains("#RRGGBB"), + "the refusal says what a colour is: {why}" + ); assert_eq!(edit.text, "zz", "the refusal keeps the text it refused"); - assert!(edit.detail().contains("zz▏"), "the caret stays in the buffer"); + assert!( + edit.detail().contains("zz▏"), + "the caret stays in the buffer" + ); // ...and the next stroke clears it: that reason described the text that is // no longer there. edit.typed('0'); @@ -1562,6 +1613,81 @@ fn every_click_door_that_writes_the_project_arms_autosave() { "{name} arms outside its gate, so a no-op pick would dirty the project" ); } + // The drag-and-drop family on the timeline: the same class, and the same + // rule. Every one of these doors can answer "nothing happened" -- a clip let + // go where it was picked up, a caption dragged back to the frame it started + // on, a trim, a fade or a `[`/`]` nudge released against the wall the edge + // already stood on, a subtitle row dropped on an overlap ("NOT PLACED") or a + // caption that is not there any more ("NOTHING LIFTED") -- and each one used + // to arm the flag *before* the door was asked, so the ledger's `unsaved` + // ghost, the autosave sidecar and the save-on-close question described a + // project whose content was byte-for-byte what it was. + // + // Each arm now rides its own door's answer, or the one reading the door's + // answer cannot give: a caption's own window before and after the trim + // (`Project::trim_sub` answers `Ok` for an edge released at a wall it already + // stood against) and the ramp's own value before and after the fade + // (`set_fade_*` answer `true` for any index that exists). + for (name, gate) in [ + ("move_clip", "match moved {"), + ( + "place_sub", + "let text = match (self.sub_of_track(track), &mut self.session) {", + ), + ("move_sub", "Some(Ok(())) => {"), + ("lift_sub", "if lifted {"), + ("commit_trim", "if trim.lane.kind == LaneKind::Subtitle {"), + ("commit_fade", "if set {"), + ("nudge_cut", "let to = nudge_edge(current, dir, lo, hi);"), + ( + "trim_cut_to_playhead", + "let to = frame_at(session.now(), self.fps);", + ), + ] { + let body = fn_body(name); + let (before, after) = body + .split_once(gate) + .unwrap_or_else(|| panic!("{name} lost the gate its arm rides")); + assert!( + after.contains("mark_dirty()"), + "{name} arms outside its gate, so a stroke that changed nothing \ + would dirty the project" + ); + assert!( + !before.contains("mark_dirty()"), + "{name} still arms ahead of its gate, so a refusal -- or a drag let \ + go where it started -- leaves the project looking edited" + ); + } + // The history pair is the one place the action table does not arm early: + // the door's own answer ("there was a step to take") is the gate, so `^z` + // with an empty history leaves the flag -- and the close question -- clear. + let act = fn_body("act"); + for gate in ["if self.undo(cx) {", "if self.redo(cx) {"] { + let after = act + .split_once(gate) + .unwrap_or_else(|| panic!("{gate} is gone from the action table")) + .1; + assert!( + after.contains("mark_dirty()"), + "the arm behind `{gate}` arms nothing, so a real step back is \ + invisible to autosave, the unsaved ghost and the close question" + ); + } + // ...and the answer the arm reads is the door's own: the session's bool, not + // a bare call that would arm for an undo with nothing to undo. + for name in ["undo", "redo"] { + let body = fn_body(name); + assert!( + body.contains("PlaybackSession::") && body.contains("stepped"), + "Player::{name} no longer answers whether there was a step to take" + ); + assert!( + !body.contains("mark_dirty"), + "Player::{name} arms its own flag, so the arm in `act` is a second \ + one for the same step" + ); + } } /// [`crate::ui::dock_stance::transition_of`]: the dock's duration row @@ -1780,11 +1906,9 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() { assert!(native_detail.ends_with(" source"), "{native_detail}"); // A project at a size nobody listed still gets the whole list, with // nothing marked rather than a wrong row marked. - assert!( - resolution_choices((1000, 1000), native) - .iter() - .all(|(.., picked)| !picked) - ); + assert!(resolution_choices((1000, 1000), native) + .iter() + .all(|(.., picked)| !picked)); // Picking a row means that row, and stepping means the next one: the // list and the stroke read the same ladder. assert_eq!(next_resolution(ladder[1], native), ladder[2]); @@ -1883,7 +2007,10 @@ fn a_choice_list_offers_every_value_and_fits_the_smallest_window() { assert!(tall <= 360., "the list is taller than the floor"); assert_eq!( menu_at(point(px(600.), px(340.)), size(px(640.), px(360.)), tall), - (640. - crate::layout::MENU_EDGE - MENU_W, 360. - crate::layout::MENU_EDGE - tall), + ( + 640. - crate::layout::MENU_EDGE - MENU_W, + 360. - crate::layout::MENU_EDGE - tall + ), "the list would hang off the smallest window" ); } @@ -2238,8 +2365,8 @@ fn maximizing_a_card_grows_its_box_without_moving_where_a_value_sits_in_it() { /// inside the dock, or hands it the dock's width again, fails this. #[test] fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() { + use crate::layout::{split_size, Split}; use crate::SPLIT_W; - use crate::layout::{Split, split_size}; // `layout::SPLIT_W` is the one divider between `stance-centre` and the // dock; the 56px rail that used to eat the centre's left edge is gone @@ -2286,7 +2413,7 @@ fn a_maximized_cards_room_is_bigger_than_the_docked_rooms_not_smaller() { /// assumption. #[test] fn a_maximized_card_can_never_rise_above_the_picture_no_matter_the_bench_height() { - use crate::ui::stance::{LEDGER_H, TIME_BAND_H, below_picture_floor}; + use crate::ui::stance::{below_picture_floor, LEDGER_H, TIME_BAND_H}; let viewport_h = 1080.; for bench_h in [140., 200., 400.] { assert_eq!(