diff --git a/crates/app/src/library_meta.rs b/crates/app/src/library_meta.rs index 6be957d..ddbe126 100644 --- a/crates/app/src/library_meta.rs +++ b/crates/app/src/library_meta.rs @@ -125,9 +125,56 @@ pub(crate) fn library_rows( }); } } + disambiguate(&mut rows); rows } +/// Two files whose rows read the same word ("2026-09-09 18-05-50" twice, user +/// 2026-09-10 -- two screen recordings) are told apart on the metadata line +/// rather than left as a pair of identical rows: the folder they came out of +/// when that differs, and a `#n` in arrival order when even the folder is +/// shared. Compared on the stem, because the stem is what the row draws. +fn disambiguate(rows: &mut [Row]) { + let named: Vec<(String, PathBuf)> = rows + .iter() + .map(|row| (crate::files::stem(&row.path), row.path.clone())) + .collect(); + for i in 0..rows.len() { + let mut twins: Vec<&PathBuf> = Vec::new(); + for (name, path) in &named { + if *name == named[i].0 && !twins.contains(&path) { + twins.push(path); + } + } + if twins.len() < 2 { + continue; + } + let folder = rows[i] + .path + .parent() + .and_then(Path::file_name) + .map(|f| f.to_string_lossy().to_string()) + .unwrap_or_default(); + let alone_in_it = twins + .iter() + .filter(|p| p.parent() == rows[i].path.parent()) + .count() + == 1; + let mark = match alone_in_it && !folder.is_empty() { + true => folder, + false => format!( + "#{}", + twins + .iter() + .position(|p| **p == rows[i].path) + .expect("a row finds itself") + + 1 + ), + }; + rows[i].detail = join_detail(&rows[i].detail, &mark); + } +} + /// The row's second line: what the stream is and then either how long it is or /// why it cannot be used, with the separator only where both halves exist (a /// single-stream file says nothing about its stream). diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index c2327eb..e0a32d8 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1292,6 +1292,97 @@ fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() { ); } +/// A file's subtitle tracks are that file's subset and are listed as one: +/// directly under the row that names it, never after every unrelated file +/// (user 2026-09-10, screenshot -- two screen recordings sat between a film +/// and its own subtitle group). A `.srt` nobody carries stays top-level, in +/// arrival order, at the end. +#[test] +fn a_file_subtitle_group_follows_its_own_row() { + use crate::ui::dock_stance::{Slot, source_list_order}; + let film = PathBuf::from("/films/a.mkv"); + let other = PathBuf::from("/rec/b.mp4"); + let loose = PathBuf::from("/subs/late.srt"); + assert_eq!( + source_list_order( + &[film.clone(), other.clone()], + &[film.clone(), loose.clone()] + ), + [Slot::Media(0), Slot::Subs(0), Slot::Media(1), Slot::Subs(1)], + "the film's own tracks must sit between it and the next file" + ); + // A file with several audio streams has several rows; the tracks follow + // the last of them, so the file's own rows stay together. + assert_eq!( + source_list_order( + &[film.clone(), other.clone(), film.clone()], + &[film.clone()] + ), + [Slot::Media(0), Slot::Media(1), Slot::Media(2), Slot::Subs(0)], + ); + // Nobody's `.srt`: still a top-level row, still last. + assert_eq!( + source_list_order(&[other], &[loose]), + [Slot::Media(0), Slot::Subs(0)], + ); +} + +/// ...and the Sources list is *built* through that ordering rather than by +/// appending the subtitle groups after the media rows, which is what put a +/// film's own tracks at the end of the list. +#[test] +fn the_sources_list_is_built_through_the_ordering() { + let dock = src_text("ui/dock_stance.rs"); + let tab = &dock[dock.find("fn sources_tab").expect("no sources tab")..]; + assert!( + tab.contains("source_list_order(&media, &subs)"), + "the Sources list no longer goes through source_list_order" + ); + assert!( + !tab.contains("row_elements.extend(subtitles)"), + "the subtitle groups are appended after every source again" + ); + // A parent already in the list gets the tracks bare, under it. + let palette = &dock[dock.find("fn subtitle_tab_rows").expect("no subtitle rows")..]; + assert!( + palette.contains("let nested = parents.contains(&group.path)") + && palette.contains("let has_header = !nested || track_count > 3"), + "a group under its own parent still draws a group row" + ); +} + +/// Two files whose rows read the same word are told apart on the metadata +/// line -- the folder, or `#n` when the folder is shared too. +#[test] +fn same_named_files_are_told_apart_on_the_metadata_line() { + let three: Vec = ["/a/rec.mp4", "/b/rec.mp4", "/a/solo.mp4"] + .into_iter() + .map(|path| Source { + path: PathBuf::from(path), + audio_stream: 0, + }) + .collect(); + let rows = library_rows(&three, &HashMap::new(), &HashMap::new(), None, |_| 90); + assert_eq!( + rows.iter().map(|row| row.detail.as_str()).collect::>(), + ["a", "b", ""], + "twins say which folder they came out of" + ); + let twins: Vec = ["/a/rec.mp4", "/a/rec.mkv"] + .into_iter() + .map(|path| Source { + path: PathBuf::from(path), + audio_stream: 0, + }) + .collect(); + let rows = library_rows(&twins, &HashMap::new(), &HashMap::new(), None, |_| 90); + assert_eq!( + rows.iter().map(|row| row.detail.as_str()).collect::>(), + ["#1", "#2"], + "one folder, one stem: arrival order tells them apart" + ); +} + /// A subtitle group's header in the Text tab must not vanish on a short /// window: `subtitle_tab_rows` draws one per group unconditionally -- there /// is no viewport-height gate on it at all any more, so the list under it diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index d012db6..161e43f 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -521,6 +521,47 @@ fn source_row( }) } +/// One entry of the Sources list, planned before anything is drawn: either a +/// media row or the subtitle group of some file. Plain data so the *order* -- +/// the branchy part -- can be tested without a window. +#[derive(Debug, PartialEq)] +pub(crate) enum Slot { + /// Index into the media rows. + Media(usize), + /// Index into the subtitle groups. + Subs(usize), +} + +/// Where each subtitle group belongs in the one Sources list: directly under +/// the source that carries it, never at the end of the list (user 2026-09-10, +/// "you put a video related subtitle to the end") -- a track that belongs to a +/// file is that file's subset and reads as one, so it follows the *last* row +/// naming that file, the way `library_rows` keeps a file's audio streams +/// together. A standalone `.srt` belongs to nobody and stays a top-level row +/// in arrival order, after the sources. +pub(crate) fn source_list_order(media: &[PathBuf], subs: &[PathBuf]) -> Vec { + let mut slots = Vec::new(); + for (i, path) in media.iter().enumerate() { + slots.push(Slot::Media(i)); + if media[i + 1..].contains(path) { + continue; // a later row still names this file; its subs go under that one + } + slots.extend( + subs.iter() + .enumerate() + .filter(|(_, sub)| *sub == path) + .map(|(j, _)| Slot::Subs(j)), + ); + } + slots.extend( + subs.iter() + .enumerate() + .filter(|(_, sub)| !media.contains(sub)) + .map(|(j, _)| Slot::Subs(j)), + ); + slots +} + /// Imported subtitle tracks, grouped by their source -- the Text tab's own /// rows (DESIGN.md's "text section ... not serving to anything", user /// 2026-08-27: relocated off the unconditional spot under the source list @@ -530,7 +571,11 @@ fn source_row( /// hover fill and selection ring -- so Text stops reading as a second /// dialect from Media/Audio. Hands back the track count for the tab header's /// own count line, same as `rows.len()` does for the other two tabs. -fn subtitle_tab_rows(player: &Player, cx: &mut Context) -> (usize, Vec) { +fn subtitle_tab_rows( + player: &Player, + parents: &[PathBuf], + cx: &mut Context, +) -> (usize, Vec<(PathBuf, usize, AnyElement)>) { let mut groups = match player.session.as_ref() { Some(session) => subtitle_rows(session.subtitles()), None => Vec::new(), @@ -574,7 +619,13 @@ fn subtitle_tab_rows(player: &Player, cx: &mut Context) -> (usize, Vec) -> (usize, Vec 3; + let folded = has_header && (nested != player.sub_folded.contains(&group_path)); + let header = div() .id(("dock-subtitle-group", group_ord)) .flex_none() .flex() .items_center() .gap(px(6.)) .px(px(8.)) + // Stepped in under its parent when it has one, the + // same outline the track rows below it read as. + .when(nested, |d| d.pl(px(22.))) .py(px(4.)) .rounded(px(3.)) .cursor_pointer() @@ -791,10 +841,19 @@ fn subtitle_tab_rows(player: &Player, cx: &mut Context) -> (usize, Vec = all_rows + let mut rows: Vec<(Row, usize)> = all_rows .into_iter() .map(|row| { let placed = player.row_ctx(&row.path, row.stream).placed; @@ -865,23 +924,49 @@ fn sources_tab( || ("unused".contains(&filter) && *placed == 0) }) .collect(); - let mut row_elements: Vec = rows - .iter() - .enumerate() - .map(|(i, (row, placed))| { - let picked = player - .selected_asset - .as_ref() - .is_some_and(|p| *p == (row.path.clone(), row.stream)); - source_row(player, i, row, *placed, picked, cx).into_any_element() - }) - .collect(); // The subtitle tracks join the same list rather than hiding behind a tab // of their own: a standalone `.srt` is a source in the sense that matters // here -- something that came in and can go on a lane -- and the tracks - // inside a container stay grouped under the file that carries them. - let (_, subtitles) = subtitle_tab_rows(player, cx); - row_elements.extend(subtitles); + // inside a container are drawn *under* that file's own row + // ([`source_list_order`]), not after every other source. + let media: Vec = rows.iter().map(|(row, _)| row.path.clone()).collect(); + let (_, subtitles) = subtitle_tab_rows(player, &media, cx); + let subs: Vec = subtitles.iter().map(|(path, ..)| path.clone()).collect(); + // Past three tracks the group under a parent arrives shut, so the count + // goes on the parent's own metadata line -- the number stays readable + // while the rows it counts are folded away. + for (i, (row, _)) in rows.iter_mut().enumerate() { + if media[i + 1..].contains(&row.path) { + continue; + } + if let Some((_, n, _)) = subtitles + .iter() + .find(|(path, n, _)| *path == row.path && *n > 3) + { + row.detail = join_detail(&row.detail, &format!("{n} subs")); + } + } + let mut subtitles: Vec> = + subtitles.into_iter().map(|(.., el)| Some(el)).collect(); + let mut row_elements: Vec = Vec::new(); + for slot in source_list_order(&media, &subs) { + match slot { + Slot::Media(i) => { + let (row, placed) = &rows[i]; + let picked = player + .selected_asset + .as_ref() + .is_some_and(|p| *p == (row.path.clone(), row.stream)); + row_elements + .push(source_row(player, i, row, *placed, picked, cx).into_any_element()); + } + Slot::Subs(j) => { + if let Some(el) = subtitles[j].take() { + row_elements.push(el); + } + } + } + } let filter_text: SharedString = player.dock_filter.clone().into(); div() .id("dock-sources")