Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(project): only closing titles at the clips' end take the last clip instant

Aditya Garud76607506df2a
diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rs
index 8624f2590..66381de2c 100644
--- a/crates/project/src/configuration.rs
+++ b/crates/project/src/configuration.rs
@@ -1872,6 +1872,10 @@ pub struct CaptionTrackSegment {
pub font_size_override: Option<u32>,
}
+/// How far a hold's start may sit from the clips' end, after float rounding,
+/// and still count as a closing title.
+const CLOSING_HOLD_TOLERANCE: f64 = 1e-9;
+
impl TimelineConfiguration {
pub fn effective_transition(&self, segment_index: usize) -> Option<ClipTransition> {
if segment_index == 0 || segment_index >= self.segments.len() {
@@ -1956,7 +1960,10 @@ impl TimelineConfiguration {
) => source,
Some(TimelineFrameMapping::Transition { incoming, .. }) => incoming,
// A closing title starts at the clips' exclusive end, so it holds their last instant.
- None => self.last_source()?,
+ None if (effective - self.clips_duration()).abs() <= CLOSING_HOLD_TOLERANCE => {
+ self.last_source()?
+ }
+ None => return None,
};
return Some(TimelineFrameMapping::Hold {
source,
@@ -2125,8 +2132,13 @@ impl TimelineConfiguration {
}
pub fn duration(&self) -> f64 {
+ self.clips_duration() + self.held_duration()
+ }
+
+ /// Output seconds covered by the clips, without fullscreen text holds.
+ fn clips_duration(&self) -> f64 {
let segment_duration: f64 = self.segments.iter().map(TimelineSegment::duration).sum();
- let segment_duration = if self.transitions.is_empty() {
+ if self.transitions.is_empty() {
segment_duration
} else {
segment_duration
@@ -2134,9 +2146,7 @@ impl TimelineConfiguration {
.filter_map(|segment_index| self.effective_transition(segment_index))
.map(|transition| transition.duration)
.sum::<f64>()
- };
-
- segment_duration + self.held_duration()
+ }
}
/// Gapless-time windows covered by clips that hide the cursor, with
diff --git a/crates/verify/tests/edits/mod.rs b/crates/verify/tests/edits/mod.rs
index 53898427a..5f4f6448c 100644
--- a/crates/verify/tests/edits/mod.rs
+++ b/crates/verify/tests/edits/mod.rs
@@ -18,7 +18,8 @@
//! - enabled fullscreen text segments are holds: the recording clock
//! pauses for their output-time window (overlapping or touching windows
//! merge), showing the frame at the hold start; the timeline grows by the
-//! held time.
+//! held time. A hold starting at the clips' end (a closing title) shows
+//! the last clip's final frame; a hold past it shows nothing.
#![allow(dead_code)]
@@ -592,7 +593,22 @@ impl TimeModel {
pub fn map(&self, o: f64) -> Option<Mapping> {
if let Some(&(a, b)) = self.holds.iter().find(|&&(a, b)| o >= a && o < b) {
- let source = self.base_map(a - self.held_before(a))?.shown();
+ let e = a - self.held_before(a);
+ let source = match self.base_map(e) {
+ Some(mapping) => mapping.shown(),
+ None if (e - self.base_duration()).abs() <= 1e-9 => {
+ let (segment, s) = self
+ .segments
+ .iter()
+ .enumerate()
+ .rfind(|(_, s)| s.duration > 0.0)?;
+ Source {
+ segment,
+ time: s.end,
+ }
+ }
+ None => return None,
+ };
return Some(Mapping::Hold {
source,
output_end: b,