forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'worktree-agent-a6ab86df59e905bdd'

Browse files at this commit

2f9d285e43bdce949827009531cfa0d7418d9ca9Ahmet Kaan GümüşParent: fbea70ae178f1e
crates/app/src/library_meta.rsmodified+47 -0
@@ -125,9 +125,56 @@ pub(crate) fn library_rows(
125 });125 });
126 }126 }
127 }127 }
128+ disambiguate(&mut rows);
128 rows129 rows
129 }130 }
130 131
132+/// Two files whose rows read the same word ("2026-09-09 18-05-50" twice, user
133+/// 2026-09-10 -- two screen recordings) are told apart on the metadata line
134+/// rather than left as a pair of identical rows: the folder they came out of
135+/// when that differs, and a `#n` in arrival order when even the folder is
136+/// shared. Compared on the stem, because the stem is what the row draws.
137+fn disambiguate(rows: &mut [Row]) {
138+ let named: Vec<(String, PathBuf)> = rows
139+ .iter()
140+ .map(|row| (crate::files::stem(&row.path), row.path.clone()))
141+ .collect();
142+ for i in 0..rows.len() {
143+ let mut twins: Vec<&PathBuf> = Vec::new();
144+ for (name, path) in &named {
145+ if *name == named[i].0 && !twins.contains(&path) {
146+ twins.push(path);
147+ }
148+ }
149+ if twins.len() < 2 {
150+ continue;
151+ }
152+ let folder = rows[i]
153+ .path
154+ .parent()
155+ .and_then(Path::file_name)
156+ .map(|f| f.to_string_lossy().to_string())
157+ .unwrap_or_default();
158+ let alone_in_it = twins
159+ .iter()
160+ .filter(|p| p.parent() == rows[i].path.parent())
161+ .count()
162+ == 1;
163+ let mark = match alone_in_it && !folder.is_empty() {
164+ true => folder,
165+ false => format!(
166+ "#{}",
167+ twins
168+ .iter()
169+ .position(|p| **p == rows[i].path)
170+ .expect("a row finds itself")
171+ + 1
172+ ),
173+ };
174+ rows[i].detail = join_detail(&rows[i].detail, &mark);
175+ }
176+}
177+
131 /// The row's second line: what the stream is and then either how long it is or178 /// The row's second line: what the stream is and then either how long it is or
132 /// why it cannot be used, with the separator only where both halves exist (a179 /// why it cannot be used, with the separator only where both halves exist (a
133 /// single-stream file says nothing about its stream).180 /// single-stream file says nothing about its stream).
crates/app/src/tests/layout.rsmodified+91 -0
@@ -1292,6 +1292,97 @@ fn the_darkroom_subtitle_palette_drags_tracks_to_subtitle_lanes() {
1292 );1292 );
1293 }1293 }
1294 1294
1295+/// A file's subtitle tracks are that file's subset and are listed as one:
1296+/// directly under the row that names it, never after every unrelated file
1297+/// (user 2026-09-10, screenshot -- two screen recordings sat between a film
1298+/// and its own subtitle group). A `.srt` nobody carries stays top-level, in
1299+/// arrival order, at the end.
1300+#[test]
1301+fn a_file_subtitle_group_follows_its_own_row() {
1302+ use crate::ui::dock_stance::{Slot, source_list_order};
1303+ let film = PathBuf::from("/films/a.mkv");
1304+ let other = PathBuf::from("/rec/b.mp4");
1305+ let loose = PathBuf::from("/subs/late.srt");
1306+ assert_eq!(
1307+ source_list_order(
1308+ &[film.clone(), other.clone()],
1309+ &[film.clone(), loose.clone()]
1310+ ),
1311+ [Slot::Media(0), Slot::Subs(0), Slot::Media(1), Slot::Subs(1)],
1312+ "the film's own tracks must sit between it and the next file"
1313+ );
1314+ // A file with several audio streams has several rows; the tracks follow
1315+ // the last of them, so the file's own rows stay together.
1316+ assert_eq!(
1317+ source_list_order(
1318+ &[film.clone(), other.clone(), film.clone()],
1319+ &[film.clone()]
1320+ ),
1321+ [Slot::Media(0), Slot::Media(1), Slot::Media(2), Slot::Subs(0)],
1322+ );
1323+ // Nobody's `.srt`: still a top-level row, still last.
1324+ assert_eq!(
1325+ source_list_order(&[other], &[loose]),
1326+ [Slot::Media(0), Slot::Subs(0)],
1327+ );
1328+}
1329+
1330+/// ...and the Sources list is *built* through that ordering rather than by
1331+/// appending the subtitle groups after the media rows, which is what put a
1332+/// film's own tracks at the end of the list.
1333+#[test]
1334+fn the_sources_list_is_built_through_the_ordering() {
1335+ let dock = src_text("ui/dock_stance.rs");
1336+ let tab = &dock[dock.find("fn sources_tab").expect("no sources tab")..];
1337+ assert!(
1338+ tab.contains("source_list_order(&media, &subs)"),
1339+ "the Sources list no longer goes through source_list_order"
1340+ );
1341+ assert!(
1342+ !tab.contains("row_elements.extend(subtitles)"),
1343+ "the subtitle groups are appended after every source again"
1344+ );
1345+ // A parent already in the list gets the tracks bare, under it.
1346+ let palette = &dock[dock.find("fn subtitle_tab_rows").expect("no subtitle rows")..];
1347+ assert!(
1348+ palette.contains("let nested = parents.contains(&group.path)")
1349+ && palette.contains("let has_header = !nested || track_count > 3"),
1350+ "a group under its own parent still draws a group row"
1351+ );
1352+}
1353+
1354+/// Two files whose rows read the same word are told apart on the metadata
1355+/// line -- the folder, or `#n` when the folder is shared too.
1356+#[test]
1357+fn same_named_files_are_told_apart_on_the_metadata_line() {
1358+ let three: Vec<Source> = ["/a/rec.mp4", "/b/rec.mp4", "/a/solo.mp4"]
1359+ .into_iter()
1360+ .map(|path| Source {
1361+ path: PathBuf::from(path),
1362+ audio_stream: 0,
1363+ })
1364+ .collect();
1365+ let rows = library_rows(&three, &HashMap::new(), &HashMap::new(), None, |_| 90);
1366+ assert_eq!(
1367+ rows.iter().map(|row| row.detail.as_str()).collect::<Vec<_>>(),
1368+ ["a", "b", ""],
1369+ "twins say which folder they came out of"
1370+ );
1371+ let twins: Vec<Source> = ["/a/rec.mp4", "/a/rec.mkv"]
1372+ .into_iter()
1373+ .map(|path| Source {
1374+ path: PathBuf::from(path),
1375+ audio_stream: 0,
1376+ })
1377+ .collect();
1378+ let rows = library_rows(&twins, &HashMap::new(), &HashMap::new(), None, |_| 90);
1379+ assert_eq!(
1380+ rows.iter().map(|row| row.detail.as_str()).collect::<Vec<_>>(),
1381+ ["#1", "#2"],
1382+ "one folder, one stem: arrival order tells them apart"
1383+ );
1384+}
1385+
1295 /// A subtitle group's header in the Text tab must not vanish on a short1386 /// A subtitle group's header in the Text tab must not vanish on a short
1296 /// window: `subtitle_tab_rows` draws one per group unconditionally -- there1387 /// window: `subtitle_tab_rows` draws one per group unconditionally -- there
1297 /// is no viewport-height gate on it at all any more, so the list under it1388 /// is no viewport-height gate on it at all any more, so the list under it
crates/app/src/ui/dock_stance.rsmodified+113 -28
@@ -521,6 +521,47 @@ fn source_row(
521 })521 })
522 }522 }
523 523
524+/// One entry of the Sources list, planned before anything is drawn: either a
525+/// media row or the subtitle group of some file. Plain data so the *order* --
526+/// the branchy part -- can be tested without a window.
527+#[derive(Debug, PartialEq)]
528+pub(crate) enum Slot {
529+ /// Index into the media rows.
530+ Media(usize),
531+ /// Index into the subtitle groups.
532+ Subs(usize),
533+}
534+
535+/// Where each subtitle group belongs in the one Sources list: directly under
536+/// the source that carries it, never at the end of the list (user 2026-09-10,
537+/// "you put a video related subtitle to the end") -- a track that belongs to a
538+/// file is that file's subset and reads as one, so it follows the *last* row
539+/// naming that file, the way `library_rows` keeps a file's audio streams
540+/// together. A standalone `.srt` belongs to nobody and stays a top-level row
541+/// in arrival order, after the sources.
542+pub(crate) fn source_list_order(media: &[PathBuf], subs: &[PathBuf]) -> Vec<Slot> {
543+ let mut slots = Vec::new();
544+ for (i, path) in media.iter().enumerate() {
545+ slots.push(Slot::Media(i));
546+ if media[i + 1..].contains(path) {
547+ continue; // a later row still names this file; its subs go under that one
548+ }
549+ slots.extend(
550+ subs.iter()
551+ .enumerate()
552+ .filter(|(_, sub)| *sub == path)
553+ .map(|(j, _)| Slot::Subs(j)),
554+ );
555+ }
556+ slots.extend(
557+ subs.iter()
558+ .enumerate()
559+ .filter(|(_, sub)| !media.contains(sub))
560+ .map(|(j, _)| Slot::Subs(j)),
561+ );
562+ slots
563+}
564+
524 /// Imported subtitle tracks, grouped by their source -- the Text tab's own565 /// Imported subtitle tracks, grouped by their source -- the Text tab's own
525 /// rows (DESIGN.md's "text section ... not serving to anything", user566 /// rows (DESIGN.md's "text section ... not serving to anything", user
526 /// 2026-08-27: relocated off the unconditional spot under the source list567 /// 2026-08-27: relocated off the unconditional spot under the source list
@@ -530,7 +571,11 @@ fn source_row(
530 /// hover fill and selection ring -- so Text stops reading as a second571 /// hover fill and selection ring -- so Text stops reading as a second
531 /// dialect from Media/Audio. Hands back the track count for the tab header's572 /// dialect from Media/Audio. Hands back the track count for the tab header's
532 /// own count line, same as `rows.len()` does for the other two tabs.573 /// own count line, same as `rows.len()` does for the other two tabs.
533-fn subtitle_tab_rows(player: &Player, cx: &mut Context<Player>) -> (usize, Vec<AnyElement>) {574+fn subtitle_tab_rows(
575+ player: &Player,
576+ parents: &[PathBuf],
577+ cx: &mut Context<Player>,
578+) -> (usize, Vec<(PathBuf, usize, AnyElement)>) {
534 let mut groups = match player.session.as_ref() {579 let mut groups = match player.session.as_ref() {
535 Some(session) => subtitle_rows(session.subtitles()),580 Some(session) => subtitle_rows(session.subtitles()),
536 None => Vec::new(),581 None => Vec::new(),
@@ -574,7 +619,13 @@ fn subtitle_tab_rows(player: &Player, cx: &mut Context<Player>) -> (usize, Vec<A
574 .into_iter()619 .into_iter()
575 .enumerate()620 .enumerate()
576 .map(|(group_ord, group)| {621 .map(|(group_ord, group)| {
577- let folded = player.sub_folded.contains(&group.path);622+ // A source already in the list is this group's parent row: its
623+ // tracks hang under it bare, with no `▸ name 1 track` row of their
624+ // own to separate them from it. Past three, the disclosure comes
625+ // back -- and arrives shut, so membership of `sub_folded` means
626+ // the editor *opened* it there.
627+ let nested = parents.contains(&group.path);
628+ let group_path = group.path.clone();
578 let fold_path = group.path.clone();629 let fold_path = group.path.clone();
579 let tint = file_tint(player.sources(), &group.path);630 let tint = file_tint(player.sources(), &group.path);
580 let track_count = group.rows.len();631 let track_count = group.rows.len();
@@ -716,19 +767,18 @@ fn subtitle_tab_rows(player: &Player, cx: &mut Context<Player>) -> (usize, Vec<A
716 )767 )
717 })768 })
718 .collect();769 .collect();
719- div()770+ let has_header = !nested || track_count > 3;
720- .flex_none()771+ let folded = has_header && (nested != player.sub_folded.contains(&group_path));
721- .flex()772+ let header = div()
722- .flex_col()
723- .gap(px(2.))
724- .child(
725- div()
726 .id(("dock-subtitle-group", group_ord))773 .id(("dock-subtitle-group", group_ord))
727 .flex_none()774 .flex_none()
728 .flex()775 .flex()
729 .items_center()776 .items_center()
730 .gap(px(6.))777 .gap(px(6.))
731 .px(px(8.))778 .px(px(8.))
779+ // Stepped in under its parent when it has one, the
780+ // same outline the track rows below it read as.
781+ .when(nested, |d| d.pl(px(22.)))
732 .py(px(4.))782 .py(px(4.))
733 .rounded(px(3.))783 .rounded(px(3.))
734 .cursor_pointer()784 .cursor_pointer()
@@ -791,10 +841,19 @@ fn subtitle_tab_rows(player: &Player, cx: &mut Context<Player>) -> (usize, Vec<A
791 "{track_count} track{}",841 "{track_count} track{}",
792 if track_count == 1 { "" } else { "s" }842 if track_count == 1 { "" } else { "s" }
793 )),843 )),
794- ),844+ );
795- )845+ (
796- .when(!folded, |d| d.children(tracks))846+ group_path,
797- .into_any_element()847+ track_count,
848+ div()
849+ .flex_none()
850+ .flex()
851+ .flex_col()
852+ .gap(px(2.))
853+ .when(has_header, |d| d.child(header))
854+ .when(!folded, |d| d.children(tracks))
855+ .into_any_element(),
856+ )
798 })857 })
799 .collect();858 .collect();
800 (count, rows)859 (count, rows)
@@ -852,7 +911,7 @@ fn sources_tab(
852 },911 },
853 );912 );
854 let filter = player.dock_filter.to_lowercase();913 let filter = player.dock_filter.to_lowercase();
855- let rows: Vec<(Row, usize)> = all_rows914+ let mut rows: Vec<(Row, usize)> = all_rows
856 .into_iter()915 .into_iter()
857 .map(|row| {916 .map(|row| {
858 let placed = player.row_ctx(&row.path, row.stream).placed;917 let placed = player.row_ctx(&row.path, row.stream).placed;
@@ -865,23 +924,49 @@ fn sources_tab(
865 || ("unused".contains(&filter) && *placed == 0)924 || ("unused".contains(&filter) && *placed == 0)
866 })925 })
867 .collect();926 .collect();
868- let mut row_elements: Vec<AnyElement> = rows
869- .iter()
870- .enumerate()
871- .map(|(i, (row, placed))| {
872- let picked = player
873- .selected_asset
874- .as_ref()
875- .is_some_and(|p| *p == (row.path.clone(), row.stream));
876- source_row(player, i, row, *placed, picked, cx).into_any_element()
877- })
878- .collect();
879 // The subtitle tracks join the same list rather than hiding behind a tab927 // The subtitle tracks join the same list rather than hiding behind a tab
880 // of their own: a standalone `.srt` is a source in the sense that matters928 // of their own: a standalone `.srt` is a source in the sense that matters
881 // here -- something that came in and can go on a lane -- and the tracks929 // here -- something that came in and can go on a lane -- and the tracks
882- // inside a container stay grouped under the file that carries them.930+ // inside a container are drawn *under* that file's own row
883- let (_, subtitles) = subtitle_tab_rows(player, cx);931+ // ([`source_list_order`]), not after every other source.
884- row_elements.extend(subtitles);932+ let media: Vec<PathBuf> = rows.iter().map(|(row, _)| row.path.clone()).collect();
933+ let (_, subtitles) = subtitle_tab_rows(player, &media, cx);
934+ let subs: Vec<PathBuf> = subtitles.iter().map(|(path, ..)| path.clone()).collect();
935+ // Past three tracks the group under a parent arrives shut, so the count
936+ // goes on the parent's own metadata line -- the number stays readable
937+ // while the rows it counts are folded away.
938+ for (i, (row, _)) in rows.iter_mut().enumerate() {
939+ if media[i + 1..].contains(&row.path) {
940+ continue;
941+ }
942+ if let Some((_, n, _)) = subtitles
943+ .iter()
944+ .find(|(path, n, _)| *path == row.path && *n > 3)
945+ {
946+ row.detail = join_detail(&row.detail, &format!("{n} subs"));
947+ }
948+ }
949+ let mut subtitles: Vec<Option<AnyElement>> =
950+ subtitles.into_iter().map(|(.., el)| Some(el)).collect();
951+ let mut row_elements: Vec<AnyElement> = Vec::new();
952+ for slot in source_list_order(&media, &subs) {
953+ match slot {
954+ Slot::Media(i) => {
955+ let (row, placed) = &rows[i];
956+ let picked = player
957+ .selected_asset
958+ .as_ref()
959+ .is_some_and(|p| *p == (row.path.clone(), row.stream));
960+ row_elements
961+ .push(source_row(player, i, row, *placed, picked, cx).into_any_element());
962+ }
963+ Slot::Subs(j) => {
964+ if let Some(el) = subtitles[j].take() {
965+ row_elements.push(el);
966+ }
967+ }
968+ }
969+ }
885 let filter_text: SharedString = player.dock_filter.clone().into();970 let filter_text: SharedString = player.dock_filter.clone().into();
886 div()971 div()
887 .id("dock-sources")972 .id("dock-sources")