From bbe4e406f230c3d94815a60e5700680bedaeb8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 13 Aug 2026 04:11:37 +0300 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=20revert(subtitles):=20the=20removal?= =?UTF-8?q?=20bin=20goes,=20the=20way=20back=20is=20the=20file's=20own=20d?= =?UTF-8?q?oor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The recovery bin was the wrong answer to the right complaint. What a person wants after removing a row is not that row back out of a session cupboard -- it is a way to put *any* file's subtitles on a timeline without importing the file, which is the door the next commit is about and which brings the removed one back as a side effect. So `Project` keeps no bin: a removal removes, as it did before, and the row's × and the notice now name the add-subtitles stroke as the way back rather than "import the file again". That old sentence does not come back: the file itself never has to be imported for its subtitles. The engine and app halves both go (b13bd53 here, and the app half that rode into 4420513 while two lanes shared one worktree). --- crates/app/src/main.rs | 75 +++------------------ crates/app/src/ui/timeline.rs | 110 +++---------------------------- crates/engine/src/playback.rs | 20 +----- crates/engine/src/project.rs | 67 +++---------------- crates/engine/tests/subtitles.rs | 76 --------------------- 5 files changed, 29 insertions(+), 319 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 227c42a..3bc4887 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -4863,10 +4863,11 @@ 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. The way - /// back is the row the removal leaves behind under the list - /// ([`Player::restore_subtitle_track`]) -- a click, not a re-import -- and - /// the notice says so rather than promising a ctrl+z that would do nothing. + /// 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. 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 @@ -4903,7 +4904,10 @@ impl Player { // ponytail: its atlas tile is not released -- `close_session`'s // note, for its reason and with its upgrade path. self.sub_image = None; - format!("{name} REMOVED — it is under the list; click it to bring it back") + format!( + "{name} REMOVED — {} puts a file's subtitles back on, the file itself stays off", + self.keymap.display(ActionId::AddSubtitleTrack) + ) } Some(Err(e)) => format!("NO SUBTITLES REMOVED — {e}"), None => "NO SUBTITLES REMOVED — open a file first".to_string(), @@ -4913,42 +4917,6 @@ impl Player { cx.notify(); } - /// The removed row's own way back: the `+` under the subtitle list, and the - /// row itself. The track goes back on the timeline with the cues it was - /// removed with ([`engine::PlaybackSession::restore_subtitles`]) -- no file - /// is read again, which is the whole complaint this answers. - /// - /// The restored track becomes the pick and the overlay goes on, for the - /// reason a click on a live row does: bringing a subtitle back is asking to - /// see it, and a restore that changed nothing on screen would read as a - /// dead row. - fn restore_subtitle_track(&mut self, removed: usize, cx: &mut Context) { - let name = self - .session - .as_ref() - .and_then(|session| sub_pick_name(session.removed_subtitles(), removed)) - .unwrap_or_else(|| format!("subtitle track {removed}")); - let text = match self - .session - .as_mut() - .map(|session| session.restore_subtitles(removed)) - { - Some(Ok(track)) => { - self.sub_track = track; - self.subs_on = true; - // The drawn cue is keyed by the pick, which has just moved -- - // `remove_subtitle_track`'s note, for its reason. - self.sub_image = None; - format!("{name} IS BACK — showing over the picture") - } - Some(Err(e)) => format!("NOTHING BROUGHT BACK — {e}"), - None => "NOTHING BROUGHT BACK — open a file first".to_string(), - }; - eprintln!("{text}"); - self.notify_user(text.into()); - cx.notify(); - } - /// Swaps the whole timeline for one restored from a `.edith`, for /// [`Player::install_media`]'s reason: the open is a worker's -- a project /// naming a 24 GB film opens that film, which is the same twenty seconds @@ -15527,31 +15495,6 @@ mod tests { assert_eq!(sub_pick_name(&[], 0), None); } - /// Whatever a removal took off can be put back from the panel, without the - /// file being imported again: the removed row and its `+` are things on - /// screen, which is what makes the way back an action and not a sentence in - /// a notice. The names on those rows come off the same - /// [`sub_pick_name`] the live ones do, so a removed track reads as the - /// track it was. - #[test] - fn a_removed_subtitle_row_has_its_way_back_in_the_panel() { - let source = ui_source(); - for id in ["subtitle-restore", "subtitle-restore-button"] { - assert!( - source.contains(&format!("\"{id}\"")), - "{id} is on no row: a removed subtitle would need a re-import" - ); - } - // What those rows are named by, off the removed list rather than the - // live one -- the bin's own indexes. - let gone = [ - sub("/films/a.mkv", Some(1), "eng"), - sub("/subs/late.srt", None, "late.srt"), - ]; - assert_eq!(sub_pick_name(&gone, 0).as_deref(), Some("eng — a")); - assert_eq!(sub_pick_name(&gone, 1).as_deref(), Some("late.srt")); - } - /// The one thing regrouping must not break: `sub_track` is a flat index /// into the add-order list, a click sets it and a save writes it into the /// `.edith`. Every row must still name the track it was made from -- rows diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 1d635d9..607b985 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -333,14 +333,13 @@ impl Player { cx: &mut Context, ) -> Option { let tracks = self.session.as_ref()?.subtitles(); - // The rows a removal left behind: still a section, because a list that - // has just been emptied is exactly when the way back has to be on - // screen. - let gone = self.session.as_ref()?.removed_subtitles(); - if tracks.is_empty() && gone.is_empty() { + if tracks.is_empty() { return None; } let groups = subtitle_rows(tracks); + // What the row's × says the way back is, in the stroke this keymap + // actually binds: a file's subtitles go on without the file. + let add_key = self.keymap.display(ActionId::AddSubtitleTrack); // One file's tracks need no prefix saying which file: it is the only // one, and every row would carry the same word. let several_files = groups.len() > 1; @@ -389,7 +388,10 @@ impl Player { // Named, because a × is the same glyph on every row and // the tooltip is what says which track it takes off. let remove_tip: SharedString = - format!("Remove {title} — it drops to the list below, one click back") + format!( + "Remove {title} — {} puts a file's subtitles back on", + add_key + ) .into(); div() // The *flat* index into the session's add-order @@ -541,99 +543,6 @@ impl Player { .children(rows) }) .collect(); - // What a removal left behind, under the live rows and dimmed: the same - // row shape with a `+` where the × was, so the way off the timeline and - // the way back on are one thing in one place. The cues are still in - // hand (`engine::PlaybackSession::removed_subtitles`), so this is a - // click and not a re-read of a 25 GB file. - let back = (!gone.is_empty()).then(|| { - let rows: Vec<_> = (0..gone.len()) - .map(|bin| { - let name = sub_pick_name(gone, bin).unwrap_or_else(|| format!("track {bin}")); - let tint = file_tint(self.sources(), &gone[bin].path); - let detail = subtitle_detail(&gone[bin]); - let tip: SharedString = - format!("Bring {name} back — the cues are still here, nothing is re-read") - .into(); - let back_tip = tip.clone(); - div() - .id(("subtitle-restore", bin)) - .flex_none() - .h(px(ROW_H)) - .flex() - .items_center() - .gap(px(6.)) - .pr(px(6.)) - .rounded(px(3.)) - .text_color(rgb(FG_SECONDARY())) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - this.restore_subtitle_track(bin, cx); - })) - .child( - div() - .flex_none() - .w(px(SWATCH_W)) - .h_full() - .rounded(px(2.)) - .opacity(0.55) - .when_some(tint, |d, tint| d.bg(rgb(tint))), - ) - .child( - div() - .flex_1() - .min_w(px(0.)) - .flex() - .flex_col() - .child(div().truncate().text_size(px(11.)).child(name)) - .child(div().truncate().text_size(px(10.)).child(detail)), - ) - // The × 's own twin: a `HIT_MIN` target at the same - // edge, and it stops the click there for the same - // reason the × does -- the row under it does the same - // thing, and a doubled restore would be a second - // notice about a row that is already back. - .child( - div() - .id(("subtitle-restore-button", bin)) - .flex_none() - .w(px(HIT_MIN)) - .h_full() - .flex() - .items_center() - .justify_center() - .rounded(px(3.)) - .cursor_pointer() - .hover(|s| s.bg(rgb(BG_HOVER()))) - .tooltip(move |_, cx| cx.new(|_| Tip(back_tip.clone())).into()) - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { - cx.stop_propagation(); - this.restore_subtitle_track(bin, cx); - })) - .child("+"), - ) - }) - .collect(); - div() - .flex_none() - .flex() - .flex_col() - .gap(px(2.)) - .child( - div() - .flex_none() - .h(px(SUB_HEAD_H)) - .flex() - .items_center() - .truncate() - .text_size(px(10.)) - .text_color(rgb(FG_SECONDARY())) - .child("Removed — click to bring one back"), - ) - .children(rows) - }); Some( div() .flex_none() @@ -665,8 +574,7 @@ impl Player { .gap(px(2.)) .max_h(px(SUB_ROWS_H)) .overflow_y_scroll() - .children(rows) - .children(back), + .children(rows), ), ) } diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index c82d64f..f420f54 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -1066,27 +1066,13 @@ 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. Not an undo step, for the - /// reason [`Project::remove_subtitles`] gives -- and not a loss either: the - /// track keeps its cues in - /// [`removed_subtitles`](Self::removed_subtitles) and - /// [`restore_subtitles`](Self::restore_subtitles) puts it back. + /// 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. pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> { self.project.remove_subtitles(idx) } - /// The tracks removed from this timeline, oldest first: what a front-end - /// lists as the way back ([`Project::removed_subtitles`]). - pub fn removed_subtitles(&self) -> &[crate::subtitle::SubtitleTrack] { - self.project.removed_subtitles() - } - - /// Brings the `idx`th removed track back, cues and all, and hands back - /// which row it is now ([`Project::restore_subtitles`]). Nothing is read - /// off disk: this is the removal undone, not the import repeated. - pub fn restore_subtitles(&mut self, idx: usize) -> crate::Result { - self.project.restore_subtitles(idx) - } - /// Writes the timeline to `path` as a `.edith`, atomically (see /// [`crate::edith`]). Sources no clip plays from are left out, and the /// playhead is saved with it so a reopened project resumes where it stood. diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 9c3b2f6..2d6a8d8 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -650,17 +650,6 @@ pub struct Project { /// it, and it is saved as a *reference* to the file the cues came out of /// ([`crate::subtitle`]). subtitles: Vec, - /// What [`Project::remove_subtitles`] took off, oldest first, cues and all - /// -- the bin [`Project::restore_subtitles`] puts one back from. A removal - /// keeps the track rather than dropping it because the cues cost a walk of - /// the whole container to read (210 ms on a 25 GB remux) and re-reading the - /// file is the one thing a person who removed a row by mistake should not - /// have to do. - /// - /// Not saved and not on the history's snapshots: a `.edith` is what the - /// timeline *has* ([`crate::edith`]), so the bin is the session's, exactly - /// as a clipboard is. - removed_subs: Vec, /// The master limiter every lane's sound is summed *through* /// ([`Project::limiter`]). Off by default, and not in the lane list, which /// is what the history snapshots hold: it is a setting on the mix, like the @@ -700,7 +689,6 @@ impl Project { history: Vec::new(), next_link: 1, subtitles: Vec::new(), - removed_subs: Vec::new(), limiter: Limiter::default(), tone: crate::tonemap::Preset::default(), } @@ -811,7 +799,6 @@ impl Project { history: Vec::new(), next_link, subtitles: Vec::new(), - removed_subs: Vec::new(), limiter: Limiter::default(), tone: crate::tonemap::Preset::default(), }) @@ -1250,56 +1237,21 @@ impl Project { /// [`crate::export::ExportSettings::subtitles`]) has to fix it up or drop /// it, or it names a different track afterwards. /// - /// Not an undo step, for the reason the limiter is not -- the history - /// snapshots hold the lane list and subtitles are not on it - /// ([`Project::subtitles`]). The way back is - /// [`restore_subtitles`](Project::restore_subtitles) and not a re-import: - /// the track goes to [`removed_subtitles`](Project::removed_subtitles) with - /// its cues, so nothing that was read has to be read again. + /// ponytail: not an undo step, for the reason the limiter is not -- the + /// history snapshots hold the lane list and subtitles are not on it + /// ([`Project::subtitles`]). The inverse is putting the file's tracks back + /// on -- [`crate::PlaybackSession::import_subtitles`], the panel's own + /// door, which reads the subtitles of a file and nothing else -- and not a + /// ctrl+z; the upgrade path is the same one the limiter has: a history + /// entry holding the project's own settings beside the lanes. pub fn remove_subtitles(&mut self, idx: usize) -> crate::Result<()> { if idx >= self.subtitles.len() { return Err(format!("there is no subtitle track {idx} to remove").into()); } - self.removed_subs.push(self.subtitles.remove(idx)); + self.subtitles.remove(idx); Ok(()) } - /// The tracks removed so far, oldest first: what a front-end lists beside - /// the live ones so a removal can be taken back - /// ([`restore_subtitles`](Project::restore_subtitles) indexes into this). - pub fn removed_subtitles(&self) -> &[SubtitleTrack] { - &self.removed_subs - } - - /// Puts the `idx`th removed track back on the timeline, cues and all, and - /// hands back which row it is now. The inverse of - /// [`remove_subtitles`](Project::remove_subtitles) and the same thing a - /// re-import of that file would have added -- minus the walk of the - /// container, which is the whole point. - /// - /// Refused by name for a bin this project does not have that many entries - /// in, exactly as a bad removal index is: a front-end holding a stale index - /// has picked the wrong row and needs to hear it. - /// - /// ponytail: it lands at the *end* of the list rather than where it was, - /// which is where a re-import would have put it too. What that costs is the - /// row order after a restore; the upgrade path is remembering the index - /// beside the track in the bin and inserting there. - pub fn restore_subtitles(&mut self, idx: usize) -> crate::Result { - if idx >= self.removed_subs.len() { - return Err(format!("there is no removed subtitle track {idx} to bring back").into()); - } - let track = self.removed_subs.remove(idx); - // `false` when the very same (file, track) was imported again while it - // sat in the bin: it is already back, and the row it is already on is - // the answer -- which the lookup below gives either way. - self.add_subtitles(&track); - self.subtitles - .iter() - .position(|t| t.path == track.path && t.track == track.track) - .ok_or_else(|| format!("{} did not go back on the timeline", track.label).into()) - } - /// What each of [`audio_segments_from`](Project::audio_segments_from)'s /// lanes is multiplied by on its way into the mix: the same lanes in the /// same order, as *amplitudes*, so the mixer never sees a decibel. `1.0` @@ -2788,9 +2740,6 @@ impl Project { history: Vec::new(), next_link: self.next_link, subtitles: self.subtitles.clone(), - // An export renders what is on the timeline: the bin is a way back - // for the window, and no render reads it. - removed_subs: Vec::new(), limiter: self.limiter, tone: self.tone, } diff --git a/crates/engine/tests/subtitles.rs b/crates/engine/tests/subtitles.rs index 49e9300..02a80c4 100644 --- a/crates/engine/tests/subtitles.rs +++ b/crates/engine/tests/subtitles.rs @@ -412,82 +412,6 @@ fn a_subtitle_row_can_be_removed_and_the_survivors_round_trip() { assert_eq!(session.subtitles().len(), 2, "and nothing moved"); } -/// The removal's inverse, which is the whole complaint: a row taken off is *in -/// hand*, not gone, and one call puts it back with the cues it left with. The -/// proof that nothing is re-read is the file itself -- it is deleted from disk -/// before the restore, and the cues still come back whole. A re-import at that -/// point could only have refused. -#[test] -fn a_removed_subtitle_row_comes_back_without_a_reimport() { - let dir = scratch("restore"); - let media = dir.join("test_av.mp4"); - std::fs::copy(asset("test_av.mp4"), &media).expect("copy the media fixture"); - for name in ["a.srt", "b.srt"] { - std::fs::copy(data("test_subs.srt"), dir.join(name)).expect("copy the subtitle fixture"); - } - - let mut session = engine::PlaybackSession::open(&media).expect("open the fixture"); - session.set_gain(0.0); - for name in ["a.srt", "b.srt"] { - session - .import_subtitles(&dir.join(name)) - .expect("the .srt imports"); - } - assert!(session.removed_subtitles().is_empty(), "nothing removed yet"); - - session.remove_subtitles(0).expect("the first row goes"); - assert_eq!(session.subtitles().len(), 1, "one row left on the timeline"); - let bin: Vec<&str> = session - .removed_subtitles() - .iter() - .map(|t| t.label.as_str()) - .collect(); - assert_eq!(bin, vec!["a.srt"], "and the removed one is listed as removed"); - assert_eq!( - session.removed_subtitles()[0].cues, - expected(), - "with its cues, so bringing it back costs no walk of the file" - ); - - // The file is gone: a re-import is not even possible from here, which is - // exactly the state a person who removed the wrong row must not be in. - std::fs::remove_file(dir.join("a.srt")).expect("delete the source file"); - - let track = session.restore_subtitles(0).expect("the row comes back"); - assert_eq!(track, 1, "back on the timeline, where a re-import would land"); - assert!( - session.removed_subtitles().is_empty(), - "and out of the removed list" - ); - let names: Vec = session - .subtitles() - .iter() - .map(|t| t.label.clone()) - .collect(); - assert_eq!(names, vec!["b.srt", "a.srt"]); - assert_eq!( - session.subtitles()[track].cues, - expected(), - "cues and all, off a file that is not there any more" - ); - - // A save writes it like any other row, and a load reads it back -- the - // restore is a track on the timeline, not a session-only ghost. (Its file - // is gone, so the load lists it refused by name, which is what a missing - // subtitle has always been.) - let project = dir.join("back.edith"); - session.save_project(&project).expect("save"); - let text = std::fs::read_to_string(&project).expect("read the project back"); - assert!(text.contains("\nsubtitle - a.srt\n"), "{text}"); - - // A bin index nobody has says so, naming it, exactly as a bad removal does. - let why = session - .restore_subtitles(0) - .expect_err("the bin is empty") - .to_string(); - assert!(why.contains('0') && why.contains("subtitle"), "{why}"); -} - /// A bitmap track survives a save the same way a text one does, and for the /// same reason: a `.edith` holds the file and the track number, never a cue, so /// what comes back is what the file still says. The pictures are read out of