From 7023001542aa03adca3fbfce0d4ec5ebe40c965b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 24 Sep 2026 14:32:25 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(player):=20a=20history=20ste?= =?UTF-8?q?p=20takes=20its=20settings=20and=20its=20pick=20back=20with=20i?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four refuted claims from the bughunt review, each a thing an undo restored in the session and left stale in everything that reads it. Engine, the order a restored step runs in: `restored_step` reseeked inside `edit` and adopted the entry's settings only afterwards, so the landing was computed from the values the step had just undone -- a rate undo clamped the playhead to the pre-undo rate's idea of the timeline's end and handed the worker the last frame for a playhead at three seconds. The closure, then `adopt_settings`, then the reseek; the same ordering reopens a proxy undo through the switch that just went back. Engine, the sweep's shape: `parts()` left the palette out, so the D4 round-trip's `parts` equality passed with `self.subtitles = prev.subtitles` deleted outright. `SubtitleTrack` compares now and `parts` carries the palette; the D4 test asserts the palette itself, which is the assertion that cannot go vacuous. App, the window's own copies: `^z`/`^y` refresh neither `self.fps` nor the two proxy switches, so after a rate undo every cut, step and fade in this window was counted at the rate just undone, the Settings rows showed a project the session no longer had, and the stale switch was pushed at the next session made. `history_step` re-reads all three off the session, which is a free function over the session because this binary has no `TestAppContext` to build a `Player` in -- `Player::undo` is the call plus the repaint. App, the subtitle pick: a `^z` of a removal restores the palette and left the pick where it was, so it named a different track than the one on screen -- the desync `sub_pick_after_removal` prevents at the removal door. The pick follows the track it names across the step (`sub_pick_after_restore`), the drawn plate is dropped when the palette or the pick moved under it, and the two docs claiming a subtitle removal is not an undo step say what it does now. --- crates/app/src/player/actions.rs | 128 ++++++++++++++++++- crates/app/src/player/library.rs | 12 +- crates/app/src/subs.rs | 59 +++++++++ crates/app/src/tests/editing.rs | 161 ++++++++++++++++++++++++ crates/app/src/tests/layout.rs | 210 ++++++++++++++++++++++--------- crates/app/src/tests/mod.rs | 63 +++++----- crates/engine/src/playback.rs | 71 +++++++++-- crates/engine/src/project.rs | 12 ++ crates/engine/src/subtitle.rs | 6 +- 9 files changed, 614 insertions(+), 108 deletions(-) diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 8f2ad31..82bd7d6 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -685,20 +685,136 @@ impl Player { } pub(crate) fn undo(&mut self, cx: &mut Context) { - if self.session.as_mut().is_some_and(PlaybackSession::undo) { - self.reset_after_reseek(); - } + self.step_history(PlaybackSession::undo); self.selected.clear(); cx.notify(); } pub(crate) fn redo(&mut self, cx: &mut Context) { - if self.session.as_mut().is_some_and(PlaybackSession::redo) { - self.reset_after_reseek(); - } + self.step_history(PlaybackSession::redo); self.selected.clear(); cx.notify(); } + + /// One step of the session's own history through the door both `^z` and + /// `^y` go through, and the window-side state it moves taken back up + /// afterwards ([`history_step`]). + /// + /// The plate the pick drew goes with the pick + /// ([`Player::remove_subtitle_track`]'s own drop, for its own reason) and + /// the frame owed to the screen is cleared + /// ([`Player::reset_after_reseek`]): an undo reseeks inside the engine, and + /// a picture left where it was is the frame before the step. + fn step_history(&mut self, step: fn(&mut PlaybackSession) -> bool) { + let mut caches = SessionCaches { + fps: self.fps, + proxies_on: self.proxies_on, + auto_proxies_on: self.auto_proxies_on, + }; + let before = HistoryBefore::of( + self.session.as_ref().map_or(&[][..], |s| s.subtitles()), + self.sub_track, + ); + let Some(outcome) = self + .session + .as_mut() + .and_then(|session| history_step(&before, &mut caches, session, step)) + else { + return; + }; + self.fps = caches.fps; + self.proxies_on = caches.proxies_on; + self.auto_proxies_on = caches.auto_proxies_on; + self.sub_track = outcome.sub_track; + if outcome.drop_sub_image { + // corner-cut: its atlas tile is not released -- `close_session`'s + // note, for its reason and with its upgrade path. + self.sub_image = None; + } + self.reset_after_reseek(); + } +} + +/// The three session settings a window keeps its own copy of, as a value so +/// that [`history_step`] can re-read them in place: the rate every +/// frame↔second conversion in the window counts in (`Player::timeline_at`, +/// `Scale::snap_frames`) and the two switches a project carries and the +/// Settings rows *show* (`settings_stance`). +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) struct SessionCaches { + pub(crate) fps: f64, + pub(crate) proxies_on: bool, + pub(crate) auto_proxies_on: bool, +} + +/// The window-side state of the palette as a history step finds it: the pick, +/// how many rows there are, and which row the pick names. +#[derive(Clone, Debug, PartialEq)] +pub(crate) struct HistoryBefore { + pub(crate) sub_track: usize, + pub(crate) sub_rows: usize, + pub(crate) sub_row: Option, +} + +impl HistoryBefore { + /// `tracks` as they stand and the index picked there -- an empty palette + /// for a window with no session, which is the state a step cannot happen in + /// anyway. + pub(crate) fn of(tracks: &[engine::subtitle::SubtitleTrack], sub_track: usize) -> Self { + Self { + sub_track, + sub_rows: tracks.len(), + sub_row: SubPickKey::of(tracks, sub_track), + } + } +} + +/// What a history step leaves this window to take up beside the session's own +/// lanes. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) struct HistoryOutcome { + pub(crate) sub_track: usize, + /// The plate the pick drew (`Player::sub_image`) was drawn through a pick + /// that no longer stands -- the palette moved under it, or it names another + /// row -- so it has to go. + pub(crate) drop_sub_image: bool, +} + +/// One step of the session's own history ([`PlaybackSession::undo`], +/// [`PlaybackSession::redo`]) with everything this window caches re-read after +/// it. `None` when the step did not happen -- nothing to undo, nothing to redo +/// -- and then nothing here moves either. +/// +/// A free function over the session and the caches rather than a [`Player`] +/// method: this test binary has no `TestAppContext` to build a `Player` in, so +/// what `^z` does to the session *and* to the caches beside it is pinned here, +/// and [`Player::step_history`] is this call plus the repaint. +/// +/// The rate and the two switches are read off the *session*, exactly as the +/// doors that own them do ([`Player::apply_frame_rate`], the `.edith` load): a +/// history entry carries the project's settings beside its lanes +/// (`Project::snapshot`), so a step puts them back -- and a window that kept +/// its old copies counts a cut at the rate just undone, keeps reporting a +/// switch the session no longer has, and pushes that switch at the next session +/// it makes. +pub(crate) fn history_step( + before: &HistoryBefore, + caches: &mut SessionCaches, + session: &mut PlaybackSession, + step: fn(&mut PlaybackSession) -> bool, +) -> Option { + if !step(session) { + return None; + } + caches.fps = session.meta().frame_rate; + caches.proxies_on = session.proxies(); + caches.auto_proxies_on = session.auto_proxies(); + let tracks = session.subtitles(); + let sub_track = sub_pick_after_restore(before.sub_track, before.sub_row.as_ref(), tracks); + Some(HistoryOutcome { + sub_track, + drop_sub_image: tracks.len() != before.sub_rows || sub_track != before.sub_track, + }) } /// The half-open range a mark and a mark make, in either order: a person's two diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index b0d0290..716047b 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -1711,11 +1711,13 @@ impl Player { /// would name a *different* track -- and the pick is what an export writes /// into the file. /// - /// Not an undo step: subtitles are not on the history's snapshots, so the - /// way back is putting the file's subtitles on again -- which is a door of - /// its own ([`Player::pick_and_add_subtitles`]) and reads the subtitles - /// alone, never the media. The notice says that rather than promising a - /// ctrl+z that would do nothing. + /// One undo step, and the palette comes back with the reindex + /// ([`engine::Project::remove_subtitles`]), so `^z` is a way back that + /// works -- [`Player::step_history`] moves the pick back with it and drops + /// the plate the old index drew. The second way back, for a caller that + /// wants the *file's* tracks again, is putting them on + /// ([`Player::pick_and_add_subtitles`]): a door of its own that reads the + /// subtitles alone, never the media, which is what the notice names. pub(crate) fn remove_subtitle_track(&mut self, track: usize, cx: &mut Context) { // The one availability oracle, for the same reason the × on a row and // the stroke are one call: an empty list is not a failure, it is an diff --git a/crates/app/src/subs.rs b/crates/app/src/subs.rs index 809d59a..dd482f5 100644 --- a/crates/app/src/subs.rs +++ b/crates/app/src/subs.rs @@ -636,6 +636,65 @@ pub(crate) fn sub_pick_after_removal(picked: usize, removed: usize, left: usize) picked.min(left.saturating_sub(1)) } +/// What a palette row *is*, apart from where it sits: the file it came out of, +/// which track of it, and the two words a row shows. Cloned out of the palette +/// once per history step -- a path and three short strings, against a palette +/// whose cues are the whole film's subtitles. Not [`SubRow`], which is a row as +/// the column *draws* it. +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct SubPickKey { + path: PathBuf, + track: Option, + language: String, + label: String, +} + +impl SubPickKey { + /// The row `track` of this palette names, `None` for an index no track + /// answers to -- the same silence [`sub_pick_name`] gives. + pub(crate) fn of(tracks: &[engine::subtitle::SubtitleTrack], track: usize) -> Option { + let track = tracks.get(track)?; + Some(Self { + path: track.path.clone(), + track: track.track, + language: track.language.clone(), + label: track.label.clone(), + }) + } + + /// Whether `track` is this row: the four fields a palette would have had to + /// change for a pick left where it was to name a different track. + fn is(&self, track: &engine::subtitle::SubtitleTrack) -> bool { + track.path == self.path + && track.track == self.track + && track.language == self.language + && track.label == self.label + } +} + +/// Where the pick lands once a *restored* palette is back in place: the row +/// that was picked, found by what it is rather than by where it sat. +/// +/// A history step moves rows without saying which one moved -- an undo of a +/// removal puts a column back above the pick as often as below it -- so an +/// index left where it was names a different track, which is the desync +/// [`sub_pick_after_removal`] prevents at the door where the row that moved is +/// known. That door's arithmetic is this map's one-row-moved case. +/// +/// A row the restored palette does not have (it went again, or the pick named +/// nothing) falls back to the old index clamped into the new list -- that same +/// door's own fallback, and the zero the section is not drawn at all for an +/// emptied palette. +pub(crate) fn sub_pick_after_restore( + picked: usize, + before: Option<&SubPickKey>, + after: &[engine::subtitle::SubtitleTrack], +) -> usize { + before + .and_then(|was| after.iter().position(|track| was.is(track))) + .unwrap_or_else(|| picked.min(after.len().saturating_sub(1))) +} + pub(crate) fn sub_pick_name( tracks: &[engine::subtitle::SubtitleTrack], track: usize, diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index 7e62a29..88d9988 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -1934,6 +1934,167 @@ fn trim_to_playhead_moves_the_selected_clips_edge_and_undoes_in_one_step() { assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the tail is back"); } +/// The window's own copy of the rate and the two switches follows the +/// *session* across `^z` and `^y`: a history entry carries the project's +/// settings beside its lanes ([`engine::Project::snapshot`]), so a step puts +/// them back -- and a window that kept its old copies counts every cut, step +/// and fade in the rate it just undid, keeps showing a switch the session no +/// longer has (`settings_stance`), and pushes that switch at the next session +/// it makes. +#[test] +fn the_windows_settings_caches_follow_the_session_across_undo_and_redo() { + use crate::player::actions::{history_step, HistoryBefore, SessionCaches}; + + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); + session.set_gain(0.0); + let native = session.meta().frame_rate; + let (proxies, auto) = (!session.proxies(), !session.auto_proxies()); + + // The three picks as the window makes them, with the copies it keeps beside + // them (`Player::apply_frame_rate`'s own write, both toggle doors'). + assert!(session.set_frame_rate(native * 2.0), "the rate pick"); + session.set_proxies(proxies); + session.set_auto_proxies(auto); + let mut caches = SessionCaches { + fps: session.meta().frame_rate, + proxies_on: proxies, + auto_proxies_on: auto, + }; + assert_ne!( + caches.fps, native, + "the test needs a rate that really moved" + ); + + // Back, one step at a time: after each one the window's copies are the + // session's, never the pick's. + for step in 0..3 { + let before = HistoryBefore::of(session.subtitles(), 0); + let out = history_step(&before, &mut caches, &mut session, PlaybackSession::undo) + .expect("a pick behind this one"); + assert_eq!( + caches.fps, + session.meta().frame_rate, + "undo {step}: the rate" + ); + assert_eq!( + caches.proxies_on, + session.proxies(), + "undo {step}: the switch" + ); + assert_eq!( + caches.auto_proxies_on, + session.auto_proxies(), + "undo {step}: the auto switch" + ); + assert!(!out.drop_sub_image, "undo {step}: no palette moved"); + } + assert_eq!(caches.fps, native, "the rate pick is undone"); + assert_eq!( + (caches.proxies_on, caches.auto_proxies_on), + (!proxies, !auto), + "and both switches are back where they were" + ); + + // ...and forward again, where the picks come home. + for step in 0..3 { + let before = HistoryBefore::of(session.subtitles(), 0); + history_step(&before, &mut caches, &mut session, PlaybackSession::redo) + .expect("a pick in front of this one"); + assert_eq!( + caches.fps, + session.meta().frame_rate, + "redo {step}: the rate" + ); + assert_eq!( + caches.proxies_on, + session.proxies(), + "redo {step}: the switch" + ); + } + assert_eq!(caches.fps, native * 2.0, "the pick's own rate is back"); + assert_eq!(caches.proxies_on, proxies, "and its switch"); +} + +/// Rows above the picked subtitle move the pick down with them +/// ([`sub_pick_after_removal`]), and a `^z` of that removal has to move it back +/// up: the palette comes home out of the entry, the pick is an *index* into it, +/// and an index left where it was names a different track -- the plate over the +/// picture would change language on its own, and the one already drawn was +/// drawn through the pick that no longer stands. +#[test] +fn the_subtitle_pick_follows_its_track_across_an_undo_of_a_removal() { + use crate::player::actions::{history_step, HistoryBefore, SessionCaches}; + + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); + session.set_gain(0.0); + assert_eq!( + session.add_subtitle_tracks(vec![ + sub("/subs/one.srt", None, "one.srt"), + sub("/subs/two.srt", None, "two.srt"), + sub("/subs/three.srt", None, "three.srt"), + ]), + 3, + "the palette" + ); + let mut caches = SessionCaches { + fps: session.meta().frame_rate, + proxies_on: session.proxies(), + auto_proxies_on: session.auto_proxies(), + }; + // The last row picked, which is where a click on it leaves the pick. + let pick = 2; + let picked = sub_pick_name(session.subtitles(), pick).expect("a name for the pick"); + + // The row *above* it goes, through the removal door's own fixup. + session + .remove_subtitles(0) + .expect("a row with nothing on it"); + let pick = sub_pick_after_removal(pick, 0, session.subtitles().len()); + assert_eq!(pick, 1, "the pick slid down with the rows"); + assert_eq!( + sub_pick_name(session.subtitles(), pick).as_deref(), + Some(picked.as_str()), + "and still names the same track" + ); + + let before = HistoryBefore::of(session.subtitles(), pick); + let out = history_step(&before, &mut caches, &mut session, PlaybackSession::undo) + .expect("the removal is a step like any other cut"); + assert_eq!(session.subtitles().len(), 3, "the palette is back"); + assert_eq!( + out.sub_track, 2, + "the row came back above the pick, so the pick moves up" + ); + assert_eq!( + sub_pick_name(session.subtitles(), out.sub_track).as_deref(), + Some(picked.as_str()), + "and still names the same track" + ); + assert_ne!( + sub_pick_name(session.subtitles(), pick).as_deref(), + Some(picked.as_str()), + "which is what the index left where it was would have named" + ); + assert!( + out.drop_sub_image, + "the drawn plate went through the pick that moved" + ); + + // ...and forward again: the removal, with the fixup it does at its own door. + let before = HistoryBefore::of(session.subtitles(), out.sub_track); + let out = history_step(&before, &mut caches, &mut session, PlaybackSession::redo) + .expect("the removal is in front of this one"); + assert_eq!( + out.sub_track, 1, + "the removal slides the pick down with the rows" + ); + assert_eq!( + sub_pick_name(session.subtitles(), out.sub_track).as_deref(), + Some(picked.as_str()) + ); + assert!(out.drop_sub_image, "and the plate goes with it"); +} + /// The oracle side of trim-to-playhead (debt #42): needs a subject cut *and* /// the playhead actually resting on it, unlike the nudge pair above it which /// only needs a cut -- the "spot" a keyless drag would snap to has to be on diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index b5ee76e..3620196 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -351,7 +351,7 @@ fn a_lane_row_is_a_fixed_header_and_a_bed_that_can_be_hit() { /// strip's row at the zoom boundary without the strip to show for it. #[test] fn the_scroll_strip_row_comes_and_goes_with_the_zoom() { - use crate::{SCROLL_HIT, Split, lanes_h, split_size, timeline_fixed_h, timeline_h}; + use crate::{lanes_h, split_size, timeline_fixed_h, timeline_h, Split, SCROLL_HIT}; use gpui::{px, size}; // The strip's row, and only the strip's row, is what the two faces differ @@ -398,8 +398,8 @@ fn the_scroll_strip_row_comes_and_goes_with_the_zoom() { /// on the track, the time axis's own thumb turned through a right angle. #[test] fn the_lane_thumb_is_the_visible_share_of_the_stack() { - use crate::SCROLL_THUMB_MIN; use crate::lanes_thumb; + use crate::SCROLL_THUMB_MIN; // Whole stack on screen: the track fills and there is nothing to scroll. assert_eq!(lanes_thumb(200., 104., 200., 0.), (0., 200.)); @@ -1301,7 +1301,7 @@ fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() { /// arrival order, at the end. #[test] fn a_file_subtitle_group_follows_its_own_row() { - use crate::ui::dock_stance::{Slot, source_list_order}; + use crate::ui::dock_stance::{source_list_order, Slot}; let film = PathBuf::from("/films/a.mkv"); let other = PathBuf::from("/rec/b.mp4"); let loose = PathBuf::from("/subs/late.srt"); @@ -1320,7 +1320,12 @@ fn a_file_subtitle_group_follows_its_own_row() { &[film.clone(), other.clone(), film.clone()], &[film.clone()] ), - [Slot::Media(0), Slot::Media(1), Slot::Media(2), Slot::Subs(0)], + [ + Slot::Media(0), + Slot::Media(1), + Slot::Media(2), + Slot::Subs(0) + ], ); // Nobody's `.srt`: still a top-level row, still last. assert_eq!( @@ -1366,7 +1371,9 @@ fn same_named_files_are_told_apart_on_the_metadata_line() { .collect(); let rows = library_rows(&three, &HashMap::new(), &HashMap::new(), None, |_| 90); assert_eq!( - rows.iter().map(|row| row.detail.as_str()).collect::>(), + rows.iter() + .map(|row| row.detail.as_str()) + .collect::>(), ["a", "b", ""], "twins say which folder they came out of" ); @@ -1379,7 +1386,9 @@ fn same_named_files_are_told_apart_on_the_metadata_line() { .collect(); let rows = library_rows(&twins, &HashMap::new(), &HashMap::new(), None, |_| 90); assert_eq!( - rows.iter().map(|row| row.detail.as_str()).collect::>(), + rows.iter() + .map(|row| row.detail.as_str()) + .collect::>(), ["#1", "#2"], "one folder, one stem: arrival order tells them apart" ); @@ -1483,6 +1492,45 @@ fn removing_a_subtitle_row_carries_the_pick_with_it() { assert_eq!(sub_pick_after_removal(0, 0, 0), 0); } +/// A `^z` moves rows without saying which one moved, so the pick is followed by +/// what it *names* ([`sub_pick_after_restore`]) rather than by its index: the +/// same three rows as the removal test above, restored instead of taken away, +/// where the index is the wrong answer in the first case and the right one in +/// the second. +#[test] +fn a_restored_palette_carries_the_pick_by_what_it_names() { + let palette = [ + sub("/films/a.mkv", Some(1), "eng"), + sub("/films/a.mkv", Some(2), "fre"), + sub("/films/a.mkv", Some(3), "ger"), + ]; + // The pick on "ger" at index 1 of the two rows a removal of the first left. + let short = [palette[1].clone(), palette[2].clone()]; + let picked = SubPickKey::of(&short, 1).expect("a row the pick names"); + assert_eq!( + sub_pick_after_restore(1, Some(&picked), &palette), + 2, + "the row above it came back" + ); + // The row that came back *below* the pick leaves it where it was. + let short = [palette[0].clone(), palette[1].clone()]; + let picked = SubPickKey::of(&short, 1).expect("a row the pick names"); + assert_eq!( + sub_pick_after_restore(1, Some(&picked), &palette), + 1, + "a row after it is not its business" + ); + // The picked row itself gone from the restored palette: the old index + // clamped into it, which is the removal door's own fallback. + let picked = SubPickKey::of(&palette, 2).expect("a row the pick names"); + assert_eq!(sub_pick_after_restore(2, Some(&picked), &palette[..2]), 1); + assert_eq!( + sub_pick_after_restore(0, None, &[]), + 0, + "an emptied palette is a state, not a panic" + ); +} + /// The same claim from the click's end, on the order imports actually /// arrive in: two films opened one after the other and an `.srt` dropped /// last interleave in the flat list, and the display reorders them. What a @@ -1707,7 +1755,11 @@ fn darkroom_lane_header_verbs_are_targeted_and_visible() { // `overlays.rs` routes those rows through the same `act_lane` door the // head's buttons used. let bench = src_text("ui/bench_stance.rs"); - for gone in ["\"bench-mix-lane\"", "\"bench-remove-lane\"", "lane.{}.remove"] { + for gone in [ + "\"bench-mix-lane\"", + "\"bench-remove-lane\"", + "lane.{}.remove", + ] { assert!(!bench.contains(gone), "the lane head still wears {gone}"); } for door in ["\"bench-show-sub-lane\"", "this.show_sub_lane(lane, cx)"] { @@ -1746,8 +1798,8 @@ fn darkroom_lane_header_verbs_are_targeted_and_visible() { fn a_dragged_divider_stops_before_either_panel_disappears() { use crate::ui::theme::INSPECTOR_MIN_W; use crate::{ - SIDE_MAX_FRAC, SPLIT_W, Split, TIMELINE_MAX_SHARE, TOOLBAR_H, inspector_w, library_w, - split_drag_size, split_size, timeline_fixed_h, timeline_h, + inspector_w, library_w, split_drag_size, split_size, timeline_fixed_h, timeline_h, Split, + SIDE_MAX_FRAC, SPLIT_W, TIMELINE_MAX_SHARE, TOOLBAR_H, }; use gpui::{point, px, size}; @@ -1867,7 +1919,7 @@ fn a_dragged_divider_stops_before_either_panel_disappears() { fn the_darkroom_seams_stop_before_either_side_disappears() { use crate::ui::theme::INSPECTOR_MIN_W; use crate::{ - BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, Split, split_bounds, split_drag_size, split_size, + split_bounds, split_drag_size, split_size, Split, BENCH_MIN_H, SIDE_MAX_FRAC, SPLIT_W, }; use gpui::{point, px, size}; @@ -1926,9 +1978,9 @@ fn the_darkroom_seams_stop_before_either_side_disappears() { /// ~2px at the old `BENCH_MIN_H = 80.`). #[test] fn both_default_lanes_fit_the_bench_at_its_floor() { - use crate::BENCH_MIN_H; - use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H, row_h}; + use crate::ui::bench_stance::{row_h, LANE_MIN_H, ROW_GAP, RULER_H}; use crate::ui::stance::BENCH_CHROME_H; + use crate::BENCH_MIN_H; let box_h = BENCH_MIN_H - BENCH_CHROME_H; let avail = box_h - RULER_H - ROW_GAP; @@ -1968,9 +2020,9 @@ fn both_default_lanes_fit_the_bench_at_its_floor() { /// painted bounds back, so it stays geometry-only, same as its neighbours. #[test] fn the_whole_bench_stack_fits_its_own_floor_with_the_ledger_seam_clear() { - use crate::BENCH_MIN_H; use crate::ui::bench_stance::{LANE_MIN_H, ROW_GAP, RULER_H}; use crate::ui::stance::BENCH_CHROME_H; + use crate::BENCH_MIN_H; const BENCH_BORDER_T: f32 = 1.; const BENCH_PY_TOP: f32 = 4.; @@ -2040,9 +2092,9 @@ fn a_lane_row_fits_what_its_own_head_draws() { #[test] fn a_saved_seam_survives_a_reload() { use crate::{ - BENCH_MIN_H, SIDE_MAX_FRAC, Split, Splits, load_stance_splits_from, save_stance_splits_to, + load_stance_splits_from, save_stance_splits_to, Split, Splits, BENCH_MIN_H, SIDE_MAX_FRAC, }; - use gpui::{Pixels, Size, px, size}; + use gpui::{px, size, Pixels, Size}; let dir = engine::scratch::Scratch::dir("edith-stance-splits"); let path = dir.join("stance-splits"); @@ -2085,7 +2137,7 @@ fn a_saved_seam_survives_a_reload() { /// drag that never started (`None`) owes nothing. #[test] fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { - use crate::{Split, player::timeline_edit::split_drag_owes_save}; + use crate::{player::timeline_edit::split_drag_owes_save, Split}; assert!(split_drag_owes_save(Some(Split::Dock))); assert!(split_drag_owes_save(Some(Split::Bench))); @@ -2099,8 +2151,8 @@ fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { /// `load_stance_splits`'s doc comment promises. #[test] fn a_missing_stance_splits_file_leaves_every_region_at_its_default() { - use crate::{Split, load_stance_splits_from}; - use gpui::{Pixels, Size, px, size}; + use crate::{load_stance_splits_from, Split}; + use gpui::{px, size, Pixels, Size}; let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing"); let window: Size = size(px(1280.), px(720.)); @@ -2182,13 +2234,7 @@ fn the_stance_renders_its_five_regions_in_the_documented_order() { // Open paren only, no close: DESIGN §12 steps 3 and 4 hand most of the // regions player/window state to read, so their call sites carry // arguments now. Order is what this asserts, not arity. - let calls = [ - "screen(", - "time_band(", - "bench(", - "ledger(", - "dock(", - ]; + let calls = ["screen(", "time_band(", "bench(", "ledger(", "dock("]; let composed: Vec = calls .iter() .map(|c| { @@ -2662,12 +2708,13 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { text.lines() .filter(|l| !l.contains("=> format!(\"{full} (global)\")")) .any(|line| { - line.match_indices(&format!("ActionId::{name}")).any(|(i, m)| { - !line[i + m.len()..] - .chars() - .next() - .is_some_and(|c| c.is_alphanumeric() || c == '_') - }) + line.match_indices(&format!("ActionId::{name}")) + .any(|(i, m)| { + !line[i + m.len()..] + .chars() + .next() + .is_some_and(|c| c.is_alphanumeric() || c == '_') + }) }) } let darkroom = [ @@ -2946,7 +2993,7 @@ fn the_bench_answers_a_wheel_notch_anywhere_over_it() { /// kept beside the first ([`Splits::clear`]). #[test] fn a_double_pressed_divider_forgets_the_size_it_was_dragged_to() { - use crate::layout::{Split, Splits, split_size}; + use crate::layout::{split_size, Split, Splits}; use gpui::{px, size}; let window = size(px(1280.), px(720.)); @@ -3007,7 +3054,8 @@ fn the_seam_paints_nothing_until_a_pointer_finds_it() { // gets after it no longer needs it (a `bench=207` -- a press with no // drag in it -- beside a dragged `dock=277`). assert!( - body.find(".group(group.clone())").expect("the band's group") + body.find(".group(group.clone())") + .expect("the band's group") < body.find("border_t_1()").expect("the hairline"), "the hairline is painted outside the band: {body}" ); @@ -3030,13 +3078,12 @@ fn the_bench_seam_reaches_no_further_than_every_other_seam() { ); } - /// The clamp table, driven: the seam refuses exactly two things, and neither /// is anywhere near where a hand drags. Measured live at 2560x1440 -- /// `bench=105` at the floor, `bench=1164` at the ceiling. #[test] fn the_bench_seam_stops_at_its_floor_and_its_ceiling() { - use crate::{BENCH_MIN_H, Split, split_bounds, split_size}; + use crate::{split_bounds, split_size, Split, BENCH_MIN_H}; use gpui::{px, size}; let window = size(px(2560.), px(1440.)); @@ -3065,8 +3112,11 @@ fn the_bench_seam_stops_at_its_floor_and_its_ceiling() { fn the_lane_bed_clips_its_clips_at_the_pinned_heads() { let src = src_text("ui/bench_stance.rs"); let start = src.find(r#".id(("bench-bed""#).expect("the bed"); - let bed = - &src[start..start + src[start..].find(".bg(rgb(DARK_CANVAS()))").expect("its fill")]; + let bed = &src[start + ..start + + src[start..] + .find(".bg(rgb(DARK_CANVAS()))") + .expect("its fill")]; assert!( bed.contains(".overflow_hidden()"), "the bed lets its clips paint outside itself, straight over the \ @@ -3130,7 +3180,10 @@ fn a_source_row_shows_its_name_before_anything_else() { "the metadata line no longer drops the decoder seat" ); let usage = &dock[dock.find("fn usage_line(").expect("the usage line")..start]; - assert!(!usage.contains("use{}"), "the metadata line still counts uses"); + assert!( + !usage.contains("use{}"), + "the metadata line still counts uses" + ); // DESIGN §8: the permanent footer telling the editor how to use a list // ("drag · ↵ add · double-click plays") is instructional copy and is gone. assert!( @@ -3183,7 +3236,10 @@ fn every_dock_body_mounts_the_ring_it_is_standing_in_for() { "the dock's key handler stops a stroke outside its tab/escape branches" ); for branch in ["is_focus_cycle_key(key)", "is_focus_exit_key(key)"] { - assert!(body.contains(branch), "{branch} left the dock's key handler"); + assert!( + body.contains(branch), + "{branch} left the dock's key handler" + ); } } @@ -3299,7 +3355,10 @@ fn a_room_ghost_wears_no_chord_that_repeats_its_name() { fn the_ledger_carries_the_rooms_four_verbs_and_no_rail_remains() { let src = src_text("ui/stance.rs"); for gone in ["stance-spine", "spine_stance", "SPINE_W", "fn spine("] { - assert!(!src.contains(gone), "the rail is still in the stance: {gone}"); + assert!( + !src.contains(gone), + "the rail is still in the stance: {gone}" + ); } let ledger = &src[src.find("fn ledger(").expect("the ledger strip") ..src.find("/// The dock:").expect("the dock frame")]; @@ -3341,8 +3400,8 @@ fn the_ledger_carries_the_rooms_four_verbs_and_no_rail_remains() { /// deletion. #[test] fn select_all_left_the_ruler_for_the_rulers_own_menu() { - use crate::ActionId; use crate::menus::BENCH_ITEMS; + use crate::ActionId; let bench = src_text("ui/bench_stance.rs"); for gone in ["bench-select-all", "select_all_band", "SELECT_ALL_PAD"] { assert!(!bench.contains(gone), "the ruler still carries {gone}"); @@ -3431,7 +3490,10 @@ fn one_name_per_source_one_stem_helper_and_one_save_door() { // a path with no name at all still reads as something. use crate::files::{file_name, stem}; use std::path::Path; - assert_eq!(stem(Path::new("/x/he_is_not_the_only_one.mp4")), "he_is_not_the_only_one"); + assert_eq!( + stem(Path::new("/x/he_is_not_the_only_one.mp4")), + "he_is_not_the_only_one" + ); assert_eq!(stem(Path::new("/x/untitled")), "untitled"); assert_eq!(stem(Path::new("/x/a.b.edith")), "a.b"); assert_eq!(stem(Path::new("/")), file_name(Path::new("/"))); @@ -3461,7 +3523,6 @@ fn the_ruler_plate_shows_the_timecode_only_while_a_scrub_is_live() { ); } - /// The band overflowed its own column at 1280x720 (`$EDITH_HITMAP`: /// `action.Export x=1113 w=80` with the column ending at x=995, the contact /// strip measured `w=0`), so the Export chip was invisible under the dock and @@ -3471,8 +3532,14 @@ fn the_ruler_plate_shows_the_timecode_only_while_a_scrub_is_live() { #[test] fn the_time_band_never_paints_outside_its_own_column() { let src = src_text("ui/timeband_stance.rs"); - let start = src.find(r#".id("stance-time-band-row")"#).expect("the band row"); - let row = &src[start..start + src[start..].find(".child(hero_timecode(").expect("the timecode")]; + let start = src + .find(r#".id("stance-time-band-row")"#) + .expect("the band row"); + let row = &src[start + ..start + + src[start..] + .find(".child(hero_timecode(") + .expect("the timecode")]; assert!( row.contains(".overflow_hidden()"), "the band row lets its children paint (and be clicked) under the dock: {row}" @@ -3518,9 +3585,16 @@ fn the_band_sheds_its_chords_and_nothing_else() { fn every_ghost_in_the_time_band_carries_a_full_hit_area() { let src = src_text("ui/timeband_stance.rs"); let start = src.find("fn ghost(").expect("the band's ghost"); - let ghost = &src[start..start + src[start..].find(".child(glyph.into())").expect("its glyph")]; + let ghost = &src[start + ..start + + src[start..] + .find(".child(glyph.into())") + .expect("its glyph")]; for needle in [".min_w(px(HIT_MIN))", ".min_h(px(HIT_MIN))"] { - assert!(ghost.contains(needle), "the band's ghost lost {needle}: {ghost}"); + assert!( + ghost.contains(needle), + "the band's ghost lost {needle}: {ghost}" + ); } assert!(HIT_MIN >= 24.); } @@ -3532,8 +3606,15 @@ fn every_ghost_in_the_time_band_carries_a_full_hit_area() { #[test] fn the_band_writes_no_monitoring_level() { let src = src_text("ui/timeband_stance.rs"); - for gone in ["player.volume.percent()", "fn volume_readout(", "fn volume_slider("] { - assert!(!src.contains(gone), "the monitoring cluster is back in the band: {gone}"); + for gone in [ + "player.volume.percent()", + "fn volume_readout(", + "fn volume_slider(", + ] { + assert!( + !src.contains(gone), + "the monitoring cluster is back in the band: {gone}" + ); } } @@ -3552,7 +3633,11 @@ fn transport_verbs_differ_by_shape_not_only_by_chord() { let mut seen = shapes.to_vec(); seen.sort(); seen.dedup(); - assert_eq!(seen.len(), shapes.len(), "two transport verbs share one glyph: {shapes:?}"); + assert_eq!( + seen.len(), + shapes.len(), + "two transport verbs share one glyph: {shapes:?}" + ); } /// DESIGN §6: "the cut readout is the odometer". Keyed off the selection it @@ -3745,7 +3830,9 @@ fn the_export_section_is_four_rows_and_no_fifth() { .find("fn export_section(") .expect("the export section"); let body = &source[start..]; - let end = body.find("\n/// The page itself").expect("the page's render fn"); + let end = body + .find("\n/// The page itself") + .expect("the page's render fn"); let body = &body[..end]; let rows = [ "settings-export-picture", @@ -3760,10 +3847,16 @@ fn the_export_section_is_four_rows_and_no_fifth() { // unrated one's readout, never both at once -- so the count is by label, // not by id. for label in ["\"Picture\"", "\"Sound\"", "\"Encoder\"", "\"Range\""] { - assert!(body.contains(label), "the EXPORT section has no {label} row"); + assert!( + body.contains(label), + "the EXPORT section has no {label} row" + ); } let ids = body.match_indices("\"settings-export-").count(); - assert_eq!(ids, 5, "the EXPORT section grew a row past the four (the two Sound rows are one row's two shapes)"); + assert_eq!( + ids, 5, + "the EXPORT section grew a row past the four (the two Sound rows are one row's two shapes)" + ); assert!( source.contains("what a delivery is written as"), "the section lost its head" @@ -3780,7 +3873,7 @@ fn the_export_section_is_four_rows_and_no_fifth() { /// cannot write, because [`Player::set_format`] would only refuse it back. #[test] fn the_picture_row_cycles_codec_and_container_together_and_skips_a_refusal() { - use crate::ui::settings_stance::{PICTURE_CYCLE, next_picture, picture_label}; + use crate::ui::settings_stance::{next_picture, picture_label, PICTURE_CYCLE}; assert_eq!( PICTURE_CYCLE, [ @@ -4017,7 +4110,6 @@ fn no_region_root_wears_a_focus_ring() { } } - /// The user could not find the three columns (2026-09-10: "I couldn't realize /// them when I look at"), because their heads were 12px `ink3` -- the room's /// quietest type -- with a prose tail running on after each one. The page's @@ -4187,9 +4279,13 @@ fn the_settings_page_is_a_centred_modal_with_one_column_of_measure() { #[test] fn the_picture_row_tail_is_the_current_format_alone() { let source = src_text("ui/settings_stance.rs"); - let start = source.find("fn export_section(").expect("the export section"); + let start = source + .find("fn export_section(") + .expect("the export section"); let body = &source[start..]; - let body = &body[..body.find("\n/// The page itself").expect("the page's render fn")]; + let body = &body[..body + .find("\n/// The page itself") + .expect("the page's render fn")]; assert!( !body.contains("PICTURE_CYCLE"), "the Picture row walks the whole cycle to build its tail again" diff --git a/crates/app/src/tests/mod.rs b/crates/app/src/tests/mod.rs index 19e70aa..ce51f9e 100644 --- a/crates/app/src/tests/mod.rs +++ b/crates/app/src/tests/mod.rs @@ -10,56 +10,55 @@ mod media; mod view; use super::{ - ACCENT_PRIMARY, AUDIO_KBPS, BG_RAISED, COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, - ColorEdit, CONTROL_H, Clip, Ctx, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, EQ_CURVE_STEPS, EQ_FFT, - EQ_FREQ_HIGH, - EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, - EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, EXPORT_DONE, Enable, - BPS_COARSE, BPS_FINE, BPS_MAX, BPS_MIN, EXPORT_MOMENT_H, EncoderSeat, FORMATS, Format, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, - KEYS_ROW_H, KEYS_W, KeyRow, LABEL_H, LANE_H, LANES_MAX, LATE_RESYNC, LIBRARY_MAX_W, - BENCH_ITEMS, LIBRARY_MIN_W, Lane, MB_FLOOR, MENU_ITEMS, MENU_PAD, - MENU_ROW_H, MENU_W, NO_FILE, NOTICES_MAX, NumberEdit, OVERLAID, PANEL_H, RESYNC_GAP, - ROW_ITEMS, RULER_HIT_H, RowCtx, RowItem, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS, + active_lane, auto_bps, band_label, bitrate_detail, clipboard_after_remove, color_snap, + containers, destructive, enable, enable_lane, envelope, eq_card_w, eq_freq, eq_freq_label, + eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, export_path, export_settings, + format_refusal, fps_choices, fps_label, frac_along, frac_down, frame_at, frame_rate_ladder, + histogram, inserted_band, is_project, keymap, keys_rows, keys_rows_matching, lane_items, + lanes_h, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play, + notice_tone, panel_h, parse_budget, project_path, proxies_to_start, push_notice, px_below, + range_word, rate_label, retarget, row_enable, row_items, scrub_due, secs_label, should_resync, + silence_rate, size_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, + sub_pick_after_removal, sub_pick_after_restore, subtitle_plan, timecode, timeline_fixed_h, + tip_may_paint, transport, typed, unseen_paths, unseen_sources, viz_held_paint, whole_take, + window_title, Clip, ColorEdit, Ctx, Enable, EncoderSeat, Format, KeyRow, Lane, NumberEdit, + RowCtx, RowItem, Source, Speed, StreamInfo, SubPickKey, Transport, VizSlot, Volume, Wave, + ACCENT_PRIMARY, AUDIO_KBPS, BENCH_ITEMS, BG_RAISED, BPS_COARSE, BPS_FINE, BPS_MAX, BPS_MIN, + COLOR_BANDS, COLOR_BAR_W, COLOR_STEP, COLOR_W, CONTROL_H, DEFAULT_AUDIO_KBPS, EQ_BANDS_MAX, + EQ_CURVE_STEPS, EQ_FFT, EQ_FREQ_HIGH, EQ_FREQ_LOW, EQ_FREQ_STEP, EQ_GAIN_LIMIT, EQ_GRAPH_H, + EQ_HANDLE, EQ_Q_HIGH, EQ_Q_LOW, EQ_Q_STEP, EQ_SPECTRUM_DB, EQ_TICKS, EQ_W_MAX, ESCAPE, + EXPORT_DONE, EXPORT_MOMENT_H, FORMATS, HEADER_H, HIST_BINS, HIST_H, HIST_SAMPLES, HIT_MIN, + KEYS_ROW_H, KEYS_W, LABEL_H, LANES_MAX, LANE_H, LATE_RESYNC, LIBRARY_MAX_W, LIBRARY_MIN_W, + MB_FLOOR, MENU_ITEMS, MENU_PAD, MENU_ROW_H, MENU_W, NOTICES_MAX, NO_FILE, OVERLAID, PANEL_H, + RESYNC_GAP, ROW_ITEMS, RULER_HIT_H, SCROLL_NOTCH_SHARE, SILENCE_ROWS, SOURCE_TINTS, SPEED_PRESETS, SPEED_STEP, STATUS_ERROR, STATUS_SUCCESS, STATUS_WARNING, SUB_PLAN_CHARS, - Source, Speed, StreamInfo, TIMELINE_SHARE, Transport, VOLUME_W, Volume, WAVE_BPS, WAVE_COL, - WAVE_COLS_MAX, Wave, ZOOM_MIN_FRAMES, active_lane, auto_bps, band_label, bitrate_detail, - clipboard_after_remove, color_snap, containers, destructive, enable, enable_lane, envelope, eq_card_w, - eq_freq, eq_freq_label, eq_graph_h, eq_spectrum, eq_x, eq_y, estimated_bytes, export_path, - export_settings, format_refusal, fps_choices, fps_label, frac_along, frac_down, - frame_at, frame_rate_ladder, histogram, inserted_band, is_project, keymap, keys_rows, keys_rows_matching, lanes_h, - lane_items, marked, menu_at, menu_items, menu_rows_h, next_container, normalise, nothing_to_play, - notice_tone, panel_h, parse_budget, project_path, range_word, proxies_to_start, push_notice, px_below, retarget, - row_enable, row_items, scrub_due, secs_label, should_resync, silence_rate, size_label, - rate_label, snap_cue, snap_marks, snapped, source_tint, span_partner, speed_at, sub_pick_after_removal, - subtitle_plan, timecode, timeline_fixed_h, tip_may_paint, - transport, typed, unseen_paths, unseen_sources, viz_held_paint, VizSlot, whole_take, - window_title, + TIMELINE_SHARE, VOLUME_W, WAVE_BPS, WAVE_COL, WAVE_COLS_MAX, ZOOM_MIN_FRAMES, }; use super::{ - ActionId, Choice, EDGE_W, ETA_SPAN, Edge, FITS, FRAME_RATES, IMPORT_STALL, Import, ImportStage, - Landing, LaneKind, PPS_DEFAULT, PPS_MIN, Preset, RESOLUTIONS, Repeat, SAMPLE_RATES, SEEK_STALL, - Scale, ScanKey, ScanPlan, SilenceScan, SubClip, View, ZOOM_OUT_MARGIN, ZOOM_STEP, arrival, - audio_rate_choices, av1_hw_warning, clip_width, clock, encoder_choices, encoder_label, + arrival, audio_rate_choices, av1_hw_warning, clip_width, clock, encoder_choices, encoder_label, eta_secs, file_name, file_uri, fit_choices, frames_of_us, full_scan_key, import_line, landing, lane_refuses, launch_queue, library_rows, live_idx, next_fit, next_resolution, note_progress, pending_fps_choices, pending_resolution_choices, px_along, read_ahead, repeats, resolution_choices, resolution_ladder, sample_rate_choices, scan_plan, seek_line, silence_cached, silence_line, slice_whole_levels, source_secs, stash_or_write, tone_choices, - tone_label, trimmed_clip, trimmed_sub, trims, unscannable, unusable, + tone_label, trimmed_clip, trimmed_sub, trims, unscannable, unusable, ActionId, Choice, Edge, + Import, ImportStage, Landing, LaneKind, Preset, Repeat, Scale, ScanKey, ScanPlan, SilenceScan, + SubClip, View, EDGE_W, ETA_SPAN, FITS, FRAME_RATES, IMPORT_STALL, PPS_DEFAULT, PPS_MIN, + RESOLUTIONS, SAMPLE_RATES, SEEK_STALL, ZOOM_OUT_MARGIN, ZOOM_STEP, }; use super::{ - SUB_BOTTOM, SUB_CUE_MIN_W, SUB_LINE_H, SUB_TEXT, Subs, carries_subtitles, cue_box, cues_at, - file_tint, is_subtitle, lang_human, sub_bottom, sub_pick_name, subtitle_detail, - subtitle_notice, subtitle_rows, subtitle_tail, subtitle_toggle_notice, walk_subtitles, + carries_subtitles, cue_box, cues_at, file_tint, is_subtitle, lang_human, sub_bottom, + sub_pick_name, subtitle_detail, subtitle_notice, subtitle_rows, subtitle_tail, + subtitle_toggle_notice, walk_subtitles, Subs, SUB_BOTTOM, SUB_CUE_MIN_W, SUB_LINE_H, SUB_TEXT, }; use engine::PlaybackSession; use engine::scale::FitPolicy; -use gpui::{Bounds, Pixels, point, px, size}; +use gpui::{point, px, size, Bounds, Pixels}; use std::collections::HashMap; diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index eaabd46..66928a7 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -1456,12 +1456,15 @@ impl PlaybackSession { /// unlike [`remove_source`](Self::remove_source) this does not reseek. Rows /// past `idx` move down by one: a caller holding a picked row (the export's /// subtitle pick) has to fix it up or drop it; the placements on the lanes - /// are walked down with it and need no fixing. Not an undo step, for the - /// reason [`Project::remove_subtitles`] gives -- the way back is - /// [`import_subtitles`](Self::import_subtitles), which reads a file's - /// subtitles and touches nothing else on the timeline -- and it *empties* - /// the undo history, because the steps in it name the tracks by the indexes - /// this call just changed. + /// are walked down with it and need no fixing. + /// + /// One undo step, and the reindex with it ([`Project::remove_subtitles`]'s + /// own entry): every step in the history names its tracks by index into the + /// palette, so an entry carries the palette it was taken beside its lanes -- + /// which is what lets a `z` put this row back, and every placement that + /// moved down with it. What that entry cannot bring back is the *pick*: it + /// is the caller's, and a caller holding one fixes it up or drops it + /// ([`crate::subs::sub_pick_after_restore`]). pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> { self.project.remove_subtitles(idx) } @@ -3723,10 +3726,17 @@ impl PlaybackSession { /// ([`Self::adopt_settings`]). Reseeks both halves, so a canvas that moved /// is repainted and a proxy switch that flipped reopens the file. fn restored_step(&mut self, f: impl FnOnce(&mut Project) -> bool) -> bool { - if !self.edit(Dirty::Both, f) { + if !f(&mut self.project) { return false; } + // Adopted *before* the reseek below, never after it: everything the + // reseek reads is one of the settings the entry just put back -- + // `landing` the rate and the frame count, `picture_path` the switches, + // the sound the sample rate -- so a landing computed from the values + // the step *undid* lands on the wrong frame of the right project (and + // reopens the file through the switch that just went back). self.adopt_settings(); + self.invalidate(Dirty::Both); true } @@ -5091,6 +5101,53 @@ mod tests { assert_eq!(next.index, first.index, "paused: same timeline position before and after"); } + /// A rate undo lands the picture where the playhead is, in the rate that + /// came *back*: the entry a pick takes carries the old numbering beside the + /// old rate, so an undo restores both and the reseek has to be computed + /// after the restore. Computed before it, the landing is the pre-undo + /// rate's reading of the post-undo project -- `now` clamps to the pre-undo + /// rate's idea of the timeline's end and the worker is handed the last + /// frame of a five-second timeline for a playhead at three seconds. + #[test] + fn a_rate_undo_reseeks_at_the_rate_it_restored() { + let mut s = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); + s.set_gain(0.0); + let poll = |s: &mut PlaybackSession| -> crate::decode::Frame { + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(20); + loop { + if let Some(f) = s.try_frame() { + return f; + } + assert!(std::time::Instant::now() < deadline, "no frame within 20s"); + std::thread::sleep(std::time::Duration::from_millis(10)); + } + }; + let native = s.native_frame_rate(); + s.seek(3.0); + assert_eq!(s.now(), 3.0, "the fixture is five seconds long"); + assert!(s.set_frame_rate(native * 2.0), "the rate pick"); + assert!(s.undo(), "the pick is one step"); + assert_eq!(s.meta().frame_rate, native, "the rate came back"); + assert_eq!( + s.now(), + 3.0, + "the playhead is the seconds it was, read at the rate that came back" + ); + // The worker's own landing, which is the half the clock alone cannot + // show: a frame 149 of 150 is exactly the pre-undo rate's clamp. + assert_eq!( + s.span.expect("a span for the picture").start, + secs_to_frame(3.0, native), + "the picture was asked for the playhead's own frame" + ); + let frame = poll(&mut s); + assert_eq!( + frame.index, + secs_to_frame(3.0, native), + "and that is the frame that arrived" + ); + } + /// The session's live look samples leave its history exactly where the /// press left it -- the colour-wheel drag's twin for the packed look, and /// what lets the app drive one from a pointer: `z` after a drag lands diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index c8b2c4d..cdeb0f9 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -116,6 +116,10 @@ pub(crate) struct SweepParts( pub(crate) usize, pub(crate) Vec<(LaneKind, Vec)>, pub(crate) Vec>, + /// The palette, which the history holds beside the lanes and an undo + /// therefore restores ([`Project::undo`]). Left out of this shape, a + /// round-trip check passed with the palette restore deleted outright. + pub(crate) Vec, pub(crate) ProjectSettings, ); @@ -5083,6 +5087,7 @@ impl Project { self.sources.len(), self.lanes.iter().map(|l| (l.kind, l.clips.clone())).collect(), self.lanes.iter().map(|l| l.subs.clone()).collect(), + self.subtitles.clone(), self.settings.clone(), ) } @@ -10569,14 +10574,21 @@ fn removing_a_subtitle_column_undoes_with_its_reindex() { .with_subtitles(vec![track("one"), track("two"), track("three")]); assert_eq!(p.subtitles().len(), 3); let before = p.parts(); + let palette = p.subtitles().to_vec(); // Column 0 goes, which renumbers the two behind it. p.remove_subtitles(0).expect("a column with nothing on it"); assert_eq!(p.subtitles().len(), 2); assert_eq!(p.subtitles()[0].label, "two"); assert!(p.undo(), "the removal is a step like any other cut"); + // The palette itself, and not only what `parts` happens to compare: this + // is the assertion that cannot go vacuous if the restore below it ever + // leaves a field of it behind. + assert_eq!(p.subtitles(), palette.as_slice(), "the palette itself, back"); assert_eq!(p.parts(), before, "the palette and the lanes, both back"); assert!(p.redo(), "and forward again"); + assert_eq!(p.subtitles().len(), 2, "the column goes again"); assert_eq!(p.subtitles()[0].label, "two"); + assert_ne!(p.subtitles(), palette.as_slice(), "and it is not back"); } } diff --git a/crates/engine/src/subtitle.rs b/crates/engine/src/subtitle.rs index 80d9b89..dd85b31 100644 --- a/crates/engine/src/subtitle.rs +++ b/crates/engine/src/subtitle.rs @@ -140,7 +140,11 @@ fn segments(set: &[u8]) -> Option> { } /// A subtitle track: where it came from and what it says. -#[derive(Clone, Debug)] +/// +/// `PartialEq` because it is one of the things an edit can change and therefore +/// one of the things an undo has to bring back exactly +/// ([`crate::Project::parts`], the sweep's round-trip). +#[derive(Clone, Debug, PartialEq, Eq)] pub struct SubtitleTrack { /// The file it was read out of: a standalone subtitle file, or the media /// file whose track number is below.