From 6830c39b3fc6a9f72d661c34aa594e6466d4148d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 14 Aug 2026 06:37:27 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(app):=20+=20S=20makes=20a=20su?= =?UTF-8?q?btitle=20track,=20and=20the=20file=20door=20keeps=20its=20own?= =?UTF-8?q?=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "if I press button +S it should create subtitle track section": it opened a file chooser instead, which is the one thing a track button never does. The button and its "s" now add a `LaneKind::Subtitle` lane exactly as + V and + A add theirs, ctrl+t takes the last one back, and the chooser survives as `ImportSubtitles` (ctrl+i) behind the Text tab's own "Add subtitles from a file…" -- the panel where the tracks it reads are listed. Every notice follows the split: an import lands rows "in the palette", a lane says "drag a subtitle from the panel onto it", and a remove with no subtitle lane says so instead of "open a file first" over an open file. The export card's Subtitles row was framed around palette picks: with an empty pick list it dropped the engine's sentence whole, so a lane the export carries nothing of said nothing at all. The sentence is kept whatever the picks are, and a row the sentence already speaks for gets no clause of its own. --- crates/app/src/keymap.rs | 43 ++++++++++++++++++--------- crates/app/src/oracle.rs | 10 +++---- crates/app/src/player/actions.rs | 13 +++++---- crates/app/src/player/library.rs | 50 +++++++++++++++++++++++++++----- crates/app/src/subs.rs | 38 +++++++++++++++++++----- crates/app/src/tests/layout.rs | 25 +++++++++++++--- crates/app/src/ui/library.rs | 6 ++-- crates/app/src/ui/timeline.rs | 5 ++-- crates/app/src/ui/toolbar.rs | 8 ++--- 9 files changed, 146 insertions(+), 52 deletions(-) diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 57f2880..ba4b42e 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -99,8 +99,13 @@ actions! { AddAudioLane, RemoveVideoLane, RemoveAudioLane, - AddSubtitleTrack, - RemoveSubtitleTrack, + AddSubtitleLane, + RemoveSubtitleLane, + /// The palette's own door: a file's subtitle tracks read into the list the + /// panel shows, which is where a lane's words are dragged *from*. Adding a + /// track to that list places nothing -- the pair above it is what makes the + /// timeline row a caption can land on. + ImportSubtitles, ToggleMute, VolumeUp, VolumeDown, @@ -172,8 +177,9 @@ impl ActionId { ActionId::AddAudioLane => "Add an audio track", ActionId::RemoveVideoLane => "Remove the last video track (it must be empty)", ActionId::RemoveAudioLane => "Remove the last audio track (it must be empty)", - ActionId::AddSubtitleTrack => "Add subtitles from a file…", - ActionId::RemoveSubtitleTrack => "Remove the picked subtitle track", + ActionId::AddSubtitleLane => "Add a subtitle track", + ActionId::RemoveSubtitleLane => "Remove the last subtitle track (it must be empty)", + ActionId::ImportSubtitles => "Add subtitles from a file…", ActionId::ToggleMute => "Mute / Unmute", ActionId::VolumeUp => "Volume up", ActionId::VolumeDown => "Volume down", @@ -228,8 +234,9 @@ impl ActionId { ActionId::AddAudioLane => "add-audio-lane", ActionId::RemoveVideoLane => "remove-video-lane", ActionId::RemoveAudioLane => "remove-audio-lane", - ActionId::AddSubtitleTrack => "add-subtitle-track", - ActionId::RemoveSubtitleTrack => "remove-subtitle-track", + ActionId::AddSubtitleLane => "add-subtitle-lane", + ActionId::RemoveSubtitleLane => "remove-subtitle-lane", + ActionId::ImportSubtitles => "import-subtitles", ActionId::ToggleMute => "toggle-mute", ActionId::VolumeUp => "volume-up", ActionId::VolumeDown => "volume-down", @@ -319,8 +326,12 @@ impl ActionId { // they add is on the timeline and goes into the file an export // writes, where the toggle two headings down only decides whether // this window draws it. - | ActionId::AddSubtitleTrack - | ActionId::RemoveSubtitleTrack + | ActionId::AddSubtitleLane + | ActionId::RemoveSubtitleLane + // ...and the door that fills the palette those lanes are dragged + // from: it edits no lane, but what it brings in is the project's + // and is saved with it, which is not a view setting. + | ActionId::ImportSubtitles | ActionId::RemoveAudioLane => Category::Editing, ActionId::ToggleMute | ActionId::VolumeUp @@ -806,8 +817,12 @@ impl Keymap { // ctrl chord takes it back. Ctrl+s is that save, so the removal // takes the other letter subtitles already answer to here: "t" // shows and hides them, and ctrl+t takes one off the timeline. - b(ActionId::AddSubtitleTrack, "s", false), - b(ActionId::RemoveSubtitleTrack, "t", true), + b(ActionId::AddSubtitleLane, "s", false), + b(ActionId::RemoveSubtitleLane, "t", true), + // Reading a file's tracks into the palette is not adding a + // track to the timeline, so it is not the bare "s": ctrl+i, the + // i of import, free and next to nothing that deletes. + b(ActionId::ImportSubtitles, "i", true), b(ActionId::ToggleMute, "m", false), // The unshifted pair, which is what gpui reports for those two // keys ("=" and "-", platform.rs:862): the volume keys every @@ -1123,7 +1138,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 51); + assert_eq!(k.entries().len(), 52); assert_eq!(k.lookup("p", true), Some(ActionId::ToggleProxies)); assert_eq!(k.lookup("o", true), Some(ActionId::ToggleAutoProxies)); assert_eq!(k.lookup("f1", false), Some(ActionId::ShowActions)); @@ -1174,8 +1189,10 @@ mod tests { assert_eq!(k.lookup("a", true), Some(ActionId::RemoveAudioLane)); // The subtitle pair, the third kind of track: the initial adds and the // subtitle letter's chord takes it back. - assert_eq!(k.lookup("s", false), Some(ActionId::AddSubtitleTrack)); - assert_eq!(k.lookup("t", true), Some(ActionId::RemoveSubtitleTrack)); + assert_eq!(k.lookup("s", false), Some(ActionId::AddSubtitleLane)); + assert_eq!(k.lookup("t", true), Some(ActionId::RemoveSubtitleLane)); + // ...and the palette's own door, which adds no track to the timeline. + assert_eq!(k.lookup("i", true), Some(ActionId::ImportSubtitles)); assert_eq!(k.lookup("m", false), Some(ActionId::ToggleMute)); assert_eq!(k.lookup("q", false), Some(ActionId::Equalizer)); // The volume pair is the unshifted one, so neither needs a modifier diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index bd6e7e6..60ffc67 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -186,11 +186,11 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { // Nothing to draw over the picture, so nothing to switch off: the // library says how subtitles arrive, and this row would flip a state // with no visible half either way. - // ...and nothing to take off the timeline either, for the same reason: - // the row would name a track that is not there. - ActionId::ToggleSubtitles | ActionId::RemoveSubtitleTrack if !ctx.subtitles => { - Enable::No("no subtitles yet") - } + // + // The × on a palette row is refused by this very fact and asks this very + // arm ([`Player::remove_subtitle_track`]): an empty list is a list with + // no row to take off, said in the same words the toggle says it in. + ActionId::ToggleSubtitles if !ctx.subtitles => Enable::No("no subtitles yet"), // Not `No`: with nothing running there is no export for this to be // about at all, which is what keeps `esc` -- the same key -- a quiet // way out of a card rather than a line about exports. diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index b631dff..2ee049d 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -73,11 +73,14 @@ impl Player { // through the × in its own header. ActionId::RemoveVideoLane => self.remove_last_lane(LaneKind::Video, cx), ActionId::RemoveAudioLane => self.remove_last_lane(LaneKind::Audio, cx), - // The same chooser the + S button opens, and the picked row -- the - // one the panel draws highlighted -- for the removal: the × on any - // other row is that row's own door, and both doors are one call. - ActionId::AddSubtitleTrack => self.pick_and_add_subtitles(cx), - ActionId::RemoveSubtitleTrack => self.remove_subtitle_track(self.sub_track, cx), + // The third kind of track, added and taken back exactly as the two + // above it: what a caption is dragged onto. The words themselves + // arrive by the door below, which places nothing. + ActionId::AddSubtitleLane => self.add_lane(LaneKind::Subtitle, cx), + ActionId::RemoveSubtitleLane => self.remove_last_lane(LaneKind::Subtitle, cx), + // The chooser the palette's own button opens: a file's tracks into + // the list, the file itself joining nothing. + ActionId::ImportSubtitles => self.pick_and_add_subtitles(cx), ActionId::ToggleMute => self.set_volume(|volume| volume.muted = !volume.muted, cx), ActionId::VolumeUp => self.set_volume(|volume| volume.step(true), cx), ActionId::VolumeDown => self.set_volume(|volume| volume.step(false), cx), diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 0c9c696..8e15b95 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -693,7 +693,7 @@ impl Player { // same question -- and *before* the chooser rather than after it: a door // that opens a dialog, waits for a file and only then says the timeline // was never there is the second door disagreeing with the first. - if let Some(why) = self.enable(ActionId::AddSubtitleTrack, None).why() { + if let Some(why) = self.enable(ActionId::ImportSubtitles, None).why() { let text = format!("NO SUBTITLES ADDED — {why}"); eprintln!("{text}"); self.notify_user(text.into()); @@ -784,12 +784,17 @@ impl Player { ) { let text = match added { Some(Ok(0)) => format!( - "{}'s subtitles are on the timeline already", + "{}'s subtitles are in the palette already", file_name(path) ), + // Where they are and what to do with them: the tracks are in the + // palette and nothing is placed until one is dragged onto an S + // track, which is the whole of what this door does. Some(Ok(n)) => format!( - "SUBTITLES {} — {n} track(s), showing over the picture, {} hides them", + "SUBTITLES {} — {n} track(s) in the palette — drag one onto an S track ({} adds \ + one), showing over the picture meanwhile, {} hides them", file_name(path), + self.keymap.display(ActionId::AddSubtitleLane), self.keymap.display(ActionId::ToggleSubtitles) ), Some(Err(e)) => format!("SUBTITLE IMPORT FAILED: {e}"), @@ -818,7 +823,10 @@ impl Player { // action with nothing to act on, and the engine's "there is no subtitle // track 0" is an index nobody typed. A real removal that fails still // says what the engine said, below. - if let Some(why) = self.enable(ActionId::RemoveSubtitleTrack, None).why() { + // The palette's list is what this takes a row off, and an empty list is + // the very fact the toggle is refused by -- so the same arm answers + // both (oracle.rs) rather than a second reading of the same state. + if let Some(why) = self.enable(ActionId::ToggleSubtitles, None).why() { let text = format!("NO SUBTITLES REMOVED — {why}"); eprintln!("{text}"); self.notify_user(text.into()); @@ -849,8 +857,9 @@ impl Player { // note, for its reason and with its upgrade path. self.sub_image = None; format!( - "{name} REMOVED — {} puts a file's subtitles back on, the file itself stays off", - self.keymap.display(ActionId::AddSubtitleTrack) + "{name} REMOVED — {} puts a file's subtitles back in the palette, the file \ + itself stays off", + self.keymap.display(ActionId::ImportSubtitles) ) } Some(Err(e)) => format!("NO SUBTITLES REMOVED — {e}"), @@ -956,8 +965,16 @@ impl Player { let lane = session.add_lane(kind); self.notify_user( format!( - "{} ADDED — drag a clip onto it, {} takes it back", + "{} ADDED — drag {} onto it, {} takes it back", lane.label(), + // A subtitle lane takes no clip at all: what lands on it + // is a palette row, so the notice names the panel the + // hand has to go to rather than "a clip", which is the + // one thing that will never work here. + match kind { + LaneKind::Subtitle => "a subtitle from the panel", + _ => "a clip", + }, self.keymap.display(ActionId::Undo) ) .into(), @@ -1079,8 +1096,25 @@ impl Player { }); match last { Some(lane) => self.remove_lane(lane, cx), + // Two different nothings: no timeline at all, and a timeline whose + // lanes of this kind have all gone -- which is the ordinary state of + // the subtitle ones, since a project starts with none. "Open a file + // first" over an open file is a notice that reads as a bug. None => { - self.notify_user("NO TRACK REMOVED — open a file first".into()); + self.notify_user( + match self.session.is_some() { + true => format!( + "NO TRACK REMOVED — there is no {} track to remove", + match kind { + LaneKind::Video => "video", + LaneKind::Audio => "audio", + LaneKind::Subtitle => "subtitle", + } + ), + false => "NO TRACK REMOVED — open a file first".to_string(), + } + .into(), + ); cx.notify(); } } diff --git a/crates/app/src/subs.rs b/crates/app/src/subs.rs index 5e0395d..07b7efa 100644 --- a/crates/app/src/subs.rs +++ b/crates/app/src/subs.rs @@ -323,17 +323,24 @@ pub(crate) fn subtitle_plan( picks: &[usize], ) -> String { let mut parts: Vec = Vec::new(); - // "none" is the engine's word for an empty pick list and would read as a - // verdict on the tracks named after it. - if !picks.is_empty() { - parts.push(plan); + // "none" is the engine's word for having nothing to say and would read as a + // verdict on the tracks named after it. Anything else is the sentence the + // export is actually planned from -- the lanes' own, wherever the timeline + // places words ([`engine::export::planned_subtitles`]) -- and it is kept + // whatever the palette picks are: dropping it on an empty pick list is how a + // card showing "S1 eng — past the last picture" said nothing at all. + if plan != "none" { + parts.push(plan.clone()); } parts.extend( tracks .iter() .enumerate() - .filter(|(i, _)| !picks.contains(i)) - .map(|(_, track)| format!("{} — no cues here", track.label)), + .filter(|(i, track)| !picks.contains(i) && !spoken_for(&plan, track)) + // Not "no cues here": a row the export leaves out is a row nothing + // on the timeline placed, and what puts that right is the drag -- + // the same sentence the import notice ends with. + .map(|(_, track)| format!("{} — in the palette, on no track", track.label)), ); let named = parts.join("; "); if named.chars().count() <= SUB_PLAN_CHARS { @@ -347,7 +354,7 @@ pub(crate) fn subtitle_plan( match ( track.refused.is_some(), track.is_bitmap(), - picks.contains(&i), + picks.contains(&i) || spoken_for(&plan, track), ) { (true, _, _) => unread += 1, (_, true, _) => pictures += 1, @@ -360,7 +367,7 @@ pub(crate) fn subtitle_plan( [ (pictures, "pictures"), (unread, "unread"), - (off, "no cues here"), + (off, "in the palette, on no track"), ] .into_iter() .filter(|(n, _)| *n > 0) @@ -369,6 +376,21 @@ pub(crate) fn subtitle_plan( counted.join("; ") } +/// Whether the engine's sentence already speaks for this row: with words placed +/// on lanes, every clause of it names the palette row its lane shows +/// ([`engine::export::planned_subtitles`]) -- and a line that embeds a track and +/// then says the same track is on no track is a line contradicting itself. +/// +/// corner-cut: the match is the label found in the sentence, because the engine +/// hands back one string and not the rows it spoke for. Ceiling: two rows whose +/// labels are one a prefix of the other ("eng", "eng 2") -- with the longer one +/// placed, the shorter loses its clause; it never gains a wrong one. Upgrade +/// path: `planned_subtitles` handing its clauses back as data, the same upgrade +/// [`subtitle_plan`]'s own note names. +fn spoken_for(plan: &str, track: &engine::subtitle::SubtitleTrack) -> bool { + !track.label.is_empty() && plan.contains(track.label.as_str()) +} + /// Every subtitle track one file gave, kept together. Plain data, planned /// before anything is drawn -- the grouping is the branchy part and it is the /// same answer whatever a styling puts around it. diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index 1da5f21..de2b254 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -759,7 +759,7 @@ fn the_card_names_the_subtitle_it_leaves_off_and_counts_them_when_it_cannot() { // What the engine answers about the one pick that reached it, and what // this side knows about the row that did not. let named = subtitle_plan("[ASS] → embedded".to_string(), &two, &[0]); - assert_eq!(named, "[ASS] → embedded; [ASS] [FOR DUB] — no cues here"); + assert_eq!(named, "[ASS] → embedded; [ASS] [FOR DUB] — in the palette, on no track"); assert!( named.chars().count() <= SUB_PLAN_CHARS, "two tracks fit the value box: {named}" @@ -778,13 +778,30 @@ fn the_card_names_the_subtitle_it_leaves_off_and_counts_them_when_it_cannot() { // and the nine picture ones, which the engine drops itself. let picks: Vec = (0..31usize).collect(); let counted = subtitle_plan("22 tracks → embedded (…)".to_string(), &many, &picks); - assert_eq!(counted, "22 of 35 → embedded; 9 pictures; 1 unread; 3 no cues here"); + assert_eq!( + counted, + "22 of 35 → embedded; 9 pictures; 1 unread; 3 in the palette, on no track" + ); assert!( counted.chars().count() <= SUB_PLAN_CHARS, "thirty-five tracks still fit the value box: {counted}" ); // Nothing on the timeline at all is still the engine's word for it. assert_eq!(subtitle_plan("none".to_string(), &[], &[]), "none"); + // The lanes are what an export writes once anything is placed on one, and + // the engine words that whole ([`engine::export::planned_subtitles`]) -- + // including the lanes it carries *nothing* of, which is a sentence with no + // pick behind it at all. That used to be dropped on the floor: the card said + // "[ASS] — no cues here" twice and never said what became of the lane. + let placed = "S1 [ASS] — past the last picture".to_string(); + assert_eq!( + subtitle_plan(placed.clone(), &two, &[]), + "S1 [ASS] — past the last picture; [ASS] [FOR DUB] — in the palette, on no track" + ); + // ...and the row that sentence speaks for gets no clause of its own: a line + // that names a lane's track and then calls the same track unplaced is the + // card contradicting itself in one breath. + assert!(!subtitle_plan(placed, &two[..1], &[]).contains("in the palette")); } /// The list is in the order tracks were added, which is not the order a @@ -884,9 +901,9 @@ fn the_text_tab_carries_the_add_subtitles_door() { let at = library .find("\"add-subtitles\"") .expect("no add-subtitles control in the library column"); - let block = &library[at..(at + 1400).min(library.len())]; + let block = &library[at..(at + 1600).min(library.len())]; assert!( - block.contains("ActionId::AddSubtitleTrack"), + block.contains("ActionId::ImportSubtitles"), "the button is a door of its own rather than the action: {block}" ); assert!( diff --git a/crates/app/src/ui/library.rs b/crates/app/src/ui/library.rs index 1e7fd82..53a4ea6 100644 --- a/crates/app/src/ui/library.rs +++ b/crates/app/src/ui/library.rs @@ -319,9 +319,9 @@ impl Player { true => "Add subtitles from a file…", false => "Add subtitles", }, - "reads a file's subtitle tracks onto this timeline — the file itself \ - joins nothing", - ActionId::AddSubtitleTrack, + "reads a file's subtitle tracks into the palette below — drag one onto an S \ + track to place it; the file itself joins nothing", + ActionId::ImportSubtitles, cx.listener(|this, _: &ClickEvent, _, cx| this.pick_and_add_subtitles(cx)), ))) }) diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 888a448..10fed9d 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -322,7 +322,7 @@ impl Player { 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); + let add_key = self.keymap.display(ActionId::ImportSubtitles); // 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; @@ -376,7 +376,8 @@ impl Player { // the tooltip is what says which track it takes off. let remove_tip: SharedString = format!( - "Remove {title} — {} puts a file's subtitles back on", + "Remove {title} from the palette — {} puts a file's subtitles \ + back in it", add_key ) .into(); diff --git a/crates/app/src/ui/toolbar.rs b/crates/app/src/ui/toolbar.rs index d268eb9..7273ca5 100644 --- a/crates/app/src/ui/toolbar.rs +++ b/crates/app/src/ui/toolbar.rs @@ -307,15 +307,15 @@ impl Player { }), )) .child(self.action_control( - "add-subtitle-track", + "add-subtitle-lane", 0., BG_RAISED(), None, "+ S", - "adds every subtitle track in a file you pick", - ActionId::AddSubtitleTrack, + "adds a subtitle track under the ones there", + ActionId::AddSubtitleLane, cx.listener(|this, _: &ClickEvent, _, cx| { - this.pick_and_add_subtitles(cx) + this.add_lane(LaneKind::Subtitle, cx) }), )) .child(separator())