Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): show hours in the recording timer and clip durations

Paddy387644bbd500
diff --git a/apps/desktop-gpui/src/controls_window.rs b/apps/desktop-gpui/src/controls_window.rs
index 4aca069a6..37a723cd7 100644
--- a/apps/desktop-gpui/src/controls_window.rs
+++ b/apps/desktop-gpui/src/controls_window.rs
@@ -130,10 +130,10 @@ impl ControlsWindow {
})
}
- /// `formatTime`: `M:SS`, hours folded into minutes the same way.
+ /// `formatTime`, through the editor clock's formatter, so a recording past
+ /// an hour reads `H:MM:SS` where the source folds the hours into minutes.
fn format_elapsed(elapsed: Duration) -> String {
- let total = elapsed.as_secs();
- format!("{}:{:02}", total / 60, total % 60)
+ crate::editor_timeline::format_time(elapsed.as_secs_f64())
}
fn action_button(
@@ -609,6 +609,16 @@ mod repaint_tests {
assert_eq!(until_next_second(Duration::ZERO), Duration::from_secs(1));
}
+ #[test]
+ fn the_timer_shows_hours_from_an_hour_on() {
+ let label = |seconds| ControlsWindow::format_elapsed(Duration::from_secs_f64(seconds));
+ assert_eq!(label(0.), "0:00");
+ assert_eq!(label(95.7), "1:35");
+ assert_eq!(label(3_599.9), "59:59");
+ assert_eq!(label(3_600.), "1:00:00");
+ assert_eq!(label(3_905.), "1:05:05");
+ }
+
#[test]
fn a_resumed_timer_wakes_at_the_next_second_and_a_paused_one_idles() {
assert_eq!(
diff --git a/apps/desktop-gpui/src/editor_clips.rs b/apps/desktop-gpui/src/editor_clips.rs
index 865968054..51ea12b75 100644
--- a/apps/desktop-gpui/src/editor_clips.rs
+++ b/apps/desktop-gpui/src/editor_clips.rs
@@ -42,7 +42,7 @@ use gpui::{
use crate::{
app_windows,
editor_edits::{self as edits, TrackSegmentOps},
- editor_timeline::clip_timeline_offsets,
+ editor_timeline::{clip_timeline_offsets, format_time},
editor_window::EditorWindow,
session::{Phase, RecordingSession},
theme::Theme,
@@ -53,13 +53,13 @@ use crate::{
// Naming (`ClipsSidebar.tsx:558-609`)
// ---------------------------------------------------------------------------
-/// `formatClipDuration` (`ClipsSidebar.tsx:79-85`).
+/// `formatClipDuration` (`ClipsSidebar.tsx:79-85`), with hours from an hour on
+/// like the editor's clock, where the source counts minutes past 59.
pub(crate) fn format_clip_duration(seconds: f64) -> String {
if !seconds.is_finite() || seconds <= 0.0 {
return "0:00".to_string();
}
- let total = seconds.round() as i64;
- format!("{}:{:02}", total / 60, total % 60)
+ format_time(seconds.round())
}
/// `clipLabel` (`:563`).
@@ -119,8 +119,8 @@ fn display_name_at(segments: &[TimelineSegment], index: usize) -> String {
}
}
-/// `segmentDescription` (`:598-609`): `m:ss`, prefixed with the parent clip's
-/// label for a split.
+/// `segmentDescription` (`:598-609`): `m:ss` (`h:mm:ss` from an hour on),
+/// prefixed with the parent clip's label for a split.
pub(crate) fn segment_description(segments: &[TimelineSegment], index: usize) -> String {
let formatted = format_clip_duration(segments[index].duration());
if segment_split_number(segments, index) > 1 {
@@ -3878,6 +3878,9 @@ mod tests {
assert_eq!(format_clip_duration(0.6), "0:01");
assert_eq!(format_clip_duration(59.6), "1:00");
assert_eq!(format_clip_duration(75.0), "1:15");
+ assert_eq!(format_clip_duration(3_599.4), "59:59");
+ assert_eq!(format_clip_duration(3_599.6), "1:00:00");
+ assert_eq!(format_clip_duration(3_905.0), "1:05:05");
assert_eq!(format_clip_duration(600.0), "10:00");
}