A caption deleted with its group closes its lane
Browse files at this commitac71b75de39475f862f052523f1717ee16fd5abcParent: 6d8f3a1- fix
- a caption deleted with its group closes its lane
1 changed file +87 -5
- crates/engine/src/project.rs +87 -5
crates/engine/src/project.rsmodified+87 -5
| @@ -4103,9 +4103,9 @@ impl Project { | |||
| 4103 | /// [`delete_in`](Project::delete_in) for the caption the pick named: a | 4103 | /// [`delete_in`](Project::delete_in) for the caption the pick named: a |
| 4104 | /// caption in no group lifts, exactly as its own key always made it | 4104 | /// caption in no group lifts, exactly as its own key always made it |
| 4105 | /// ([`Project::lift_sub`]), and a caption in a group takes the group with | 4105 | /// ([`Project::lift_sub`]), and a caption in a group takes the group with |
| 4106 | - /// it by [`delete_in`](Project::delete_in)'s rule -- the media members' | 4106 | + /// it by [`delete_in`](Project::delete_in)'s rule -- every member's own |
| 4107 | - /// spans out of their own lanes, the other captions lifted. `false` for a | 4107 | + /// span out of its own lane, hole closed, captions and clips alike. |
| 4108 | - /// bad index. | 4108 | + /// `false` for a bad index. |
| 4109 | pub fn delete_sub_in(&mut self, lane: Lane, idx: usize) -> bool { | 4109 | pub fn delete_sub_in(&mut self, lane: Lane, idx: usize) -> bool { |
| 4110 | let Some(members) = self.group_of(lane, idx) else { | 4110 | let Some(members) = self.group_of(lane, idx) else { |
| 4111 | return false; | 4111 | return false; |
| @@ -4127,8 +4127,17 @@ impl Project { | |||
| 4127 | let c = self.lanes[l].clips[i]; | 4127 | let c = self.lanes[l].clips[i]; |
| 4128 | ripple(&mut self.lanes, &[l], c.start, c.frames()); | 4128 | ripple(&mut self.lanes, &[l], c.start, c.frames()); |
| 4129 | } | 4129 | } |
| 4130 | - for &(l, i) in members.subs.iter().rev() { | 4130 | + // The captions go by the same law their clip siblings do -- the span |
| 4131 | - self.lanes[l].subs.remove(i); | 4131 | + // out of its own lane, the hole closed -- and not by the lift a |
| 4132 | + // *lone* caption's delete is: deleted with its group, the words after | ||
| 4133 | + // it slide up with everything else, or the lane the group emptied is | ||
| 4134 | + // the one lane the delete left a hole in. `ripple` is the one | ||
| 4135 | + // mechanism (it clears the span and shifts the rest, clips and | ||
| 4136 | + // captions alike); a sub lane holds no clips, so its other list is | ||
| 4137 | + // untouched. | ||
| 4138 | + for &(l, i) in &members.subs { | ||
| 4139 | + let s = self.lanes[l].subs[i]; | ||
| 4140 | + ripple(&mut self.lanes, &[l], s.start, s.frames); | ||
| 4132 | } | 4141 | } |
| 4133 | debug_assert!(links_are_consistent(&self.lanes).is_ok()); | 4142 | debug_assert!(links_are_consistent(&self.lanes).is_ok()); |
| 4134 | true | 4143 | true |
| @@ -5670,6 +5679,79 @@ mod tests { | |||
| 5670 | assert_eq!(p.sub_lane(s1)[0].start, 2, "offsets and all"); | 5679 | assert_eq!(p.sub_lane(s1)[0].start, 2, "offsets and all"); |
| 5671 | } | 5680 | } |
| 5672 | 5681 | ||
| 5682 | + /// The delete law, one statement for every anchor: a caption deleted | ||
| 5683 | + /// WITH its group ripples its lane exactly as its clip siblings do -- | ||
| 5684 | + /// the hole closes and what follows slides up -- while a caption lifted | ||
| 5685 | + /// alone leaves its gap, as it always has. And the delete of a grouped | ||
| 5686 | + /// clip takes the group from whichever member was clicked. | ||
| 5687 | + #[test] | ||
| 5688 | + fn a_grouped_delete_closes_the_caption_lane_and_takes_the_group_from_every_anchor() { | ||
| 5689 | + let caption = |start: u32, frames: u32| SubClip { | ||
| 5690 | + start, | ||
| 5691 | + frames, | ||
| 5692 | + track: 0, | ||
| 5693 | + in_us: 0, | ||
| 5694 | + out_us: i64::from(frames) * 1_000_000, | ||
| 5695 | + link: None, | ||
| 5696 | + }; | ||
| 5697 | + let track = || SubtitleTrack { | ||
| 5698 | + path: FILE.into(), | ||
| 5699 | + track: None, | ||
| 5700 | + language: "eng".into(), | ||
| 5701 | + name: String::new(), | ||
| 5702 | + label: "eng".into(), | ||
| 5703 | + cues: Vec::new(), | ||
| 5704 | + bitmap: false, | ||
| 5705 | + refused: None, | ||
| 5706 | + }; | ||
| 5707 | + // V+A+S grouped, with a second caption BEHIND the group's caption: | ||
| 5708 | + // closing the hole is what the second caption's position says. | ||
| 5709 | + let group = || { | ||
| 5710 | + let mut p = Project::single(FILE, 90).with_subtitles(vec![track()]); | ||
| 5711 | + let s1 = p.add_lane(LaneKind::Subtitle); | ||
| 5712 | + p.place_sub(s1, 30, caption(30, 30)).expect("the group's caption"); | ||
| 5713 | + p.place_sub(s1, 90, caption(90, 30)).expect("the caption behind"); | ||
| 5714 | + p.group_all(&[(Lane::V1, 0), (s1, 0)]).expect("grouped"); | ||
| 5715 | + (p, s1) | ||
| 5716 | + }; | ||
| 5717 | + | ||
| 5718 | + // Deleted by the picture: all three lanes close. | ||
| 5719 | + let (mut p, s1) = group(); | ||
| 5720 | + assert!(p.delete_in(Lane::V1, 0)); | ||
| 5721 | + assert!(p.lane(Lane::V1).is_empty(), "the clip's span left V1"); | ||
| 5722 | + assert!(p.lane(Lane::A1).is_empty(), "and the sound's"); | ||
| 5723 | + assert_eq!( | ||
| 5724 | + p.sub_lane(s1).iter().map(|s| s.start).collect::<Vec<_>>(), | ||
| 5725 | + [60], | ||
| 5726 | + "the caption's lane closed by its own span: the follower slid up" | ||
| 5727 | + ); | ||
| 5728 | + assert!(p.undo(), "one step"); | ||
| 5729 | + assert_eq!(p.sub_lane(s1).len(), 2, "both captions back, offsets and all"); | ||
| 5730 | + | ||
| 5731 | + // By the sound: the same whole-group delete. | ||
| 5732 | + let (mut p, s1) = group(); | ||
| 5733 | + assert!(p.delete_in(Lane::A1, 0)); | ||
| 5734 | + assert!(p.lane(Lane::V1).is_empty() && p.lane(Lane::A1).is_empty()); | ||
| 5735 | + assert_eq!(p.sub_lane(s1)[0].start, 60, "the caption lane closed too"); | ||
| 5736 | + | ||
| 5737 | + // By the caption itself: the same again. | ||
| 5738 | + let (mut p, s1) = group(); | ||
| 5739 | + assert!(p.delete_sub_in(s1, 0)); | ||
| 5740 | + assert!(p.lane(Lane::V1).is_empty() && p.lane(Lane::A1).is_empty()); | ||
| 5741 | + assert_eq!(p.sub_lane(s1)[0].start, 60, "closed from the caption's own door"); | ||
| 5742 | + assert!(links_are_consistent(&p.lanes).is_ok()); | ||
| 5743 | + | ||
| 5744 | + // A caption lifted ALONE still leaves its gap: the ungrouped law, | ||
| 5745 | + // unchanged. | ||
| 5746 | + let (mut p, s1) = group(); | ||
| 5747 | + assert!(p.ungroup(s1, 0), "the caption stands alone"); | ||
| 5748 | + assert!(p.lift_sub(s1, 0)); | ||
| 5749 | + assert_eq!( | ||
| 5750 | + p.sub_lane(s1)[0].start, 90, | ||
| 5751 | + "the follower stayed put: a lone caption's lift is a gap" | ||
| 5752 | + ); | ||
| 5753 | + } | ||
| 5754 | + | ||
| 5673 | /// Dragging a grouped caption carries its clips, one delta for all of them | 5755 | /// Dragging a grouped caption carries its clips, one delta for all of them |
| 5674 | /// -- and a caption in no group refuses an overlap exactly as it always did. | 5756 | /// -- and a caption in no group refuses an overlap exactly as it always did. |
| 5675 | #[test] | 5757 | #[test] |