Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/desktop-gpui/locales/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ label = "Automatisch auf Klicks zoomen"
description = "Zoomstufe für neu erstellte und automatisch erzeugte Zoom-Segmente."
label = "Standard-Zoomstufe"

[settings.general.recording.auto_zoom_hold]
description = "Wie lange automatisch erzeugte Zoom-Segmente nach jedem Klick gezoomt bleiben."
label = "Zoom-Haltedauer nach Klick"

[settings.general.recording.auto_zoom_merge_gap]
description = "Aufeinanderfolgende Klick-Zooms mit kleinerem Abstand zusammenführen. Auf 0s setzen, um Lücken nie zusammenzuführen."
label = "Abstand zum Zusammenführen naher Klicks"

[settings.general.recording.capture_keyboard]
description = "Tastenanschläge aufzeichnen, damit Sie im Editor Tastatur-Overlays hinzufügen können."
label = "Tastenanschläge aufzeichnen"
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop-gpui/locales/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ label = "Auto zoom on clicks"
description = "Zoom level for newly created and auto-generated zoom segments."
label = "Default zoom amount"

[settings.general.recording.auto_zoom_hold]
description = "How long auto-generated zoom segments stay zoomed in after each click."
label = "Zoom hold after click"

[settings.general.recording.auto_zoom_merge_gap]
description = "Merge consecutive click zooms separated by less than this gap. Set to 0s to never merge gaps."
label = "Merge nearby clicks gap"

[settings.general.recording.capture_keyboard]
description = "Record key presses so you can add keyboard overlays in the editor."
label = "Capture keyboard presses"
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop-gpui/locales/es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ label = "Zoom automático en los clics"
description = "Nivel de zoom de los segmentos de zoom nuevos y generados automáticamente."
label = "Nivel de zoom predeterminado"

[settings.general.recording.auto_zoom_hold]
description = "Cuánto tiempo permanecen acercados los segmentos de zoom automáticos después de cada clic."
label = "Duración del zoom tras clic"

[settings.general.recording.auto_zoom_merge_gap]
description = "Combina zooms de clics consecutivos separados por menos de este intervalo. Ajusta a 0s para no combinar huecos."
label = "Intervalo para combinar clics cercanos"

[settings.general.recording.capture_keyboard]
description = "Registra las pulsaciones de teclas para poder añadir superposiciones de teclado en el editor."
label = "Capturar pulsaciones de teclas"
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop-gpui/locales/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ label = "Zoom automatique sur les clics"
description = "Niveau de zoom des segments de zoom créés manuellement ou automatiquement."
label = "Niveau de zoom par défaut"

[settings.general.recording.auto_zoom_hold]
description = "Durée pendant laquelle les segments de zoom automatiques restent zoomés après chaque clic."
label = "Maintien du zoom après un clic"

[settings.general.recording.auto_zoom_merge_gap]
description = "Fusionner les zooms de clics consécutifs séparés par moins que cet écart. Régler sur 0s pour ne jamais fusionner les écarts."
label = "Écart de fusion des clics proches"

[settings.general.recording.capture_keyboard]
description = "Enregistrer les frappes au clavier pour pouvoir ajouter des incrustations de touches dans l'éditeur."
label = "Capturer les frappes au clavier"
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop-gpui/locales/hi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ label = "क्लिक पर ऑटो ज़ूम"
description = "नए बनाए गए और अपने-आप बने ज़ूम सेगमेंट का ज़ूम स्तर।"
label = "डिफ़ॉल्ट ज़ूम स्तर"

[settings.general.recording.auto_zoom_hold]
description = "हर क्लिक के बाद अपने-आप बने ज़ूम सेगमेंट कितनी देर तक ज़ूम रहते हैं।"
label = "क्लिक के बाद ज़ूम होल्ड"

[settings.general.recording.auto_zoom_merge_gap]
description = "इस अंतर से कम दूरी वाले लगातार क्लिक ज़ूम को मिलाएँ। अंतर कभी न मिलाने के लिए 0s पर सेट करें।"
label = "पास के क्लिक मिलाने का अंतर"

[settings.general.recording.capture_keyboard]
description = "की प्रेस रिकॉर्ड करें, ताकि आप एडिटर में कीबोर्ड ओवरले जोड़ सकें।"
label = "कीबोर्ड प्रेस कैप्चर करें"
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop-gpui/locales/ja.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ label = "クリック時に自動ズーム"
description = "新しく作成したズームセグメントと自動生成されたズームセグメントの倍率。"
label = "デフォルトのズーム倍率"

[settings.general.recording.auto_zoom_hold]
description = "各クリック後に自動生成されたズームセグメントが維持される時間。"
label = "クリック後のズーム維持時間"

[settings.general.recording.auto_zoom_merge_gap]
description = "この間隔より短い連続したクリックズームを結合します。0s に設定すると間隔を結合しません。"
label = "近接クリックの結合間隔"

[settings.general.recording.capture_keyboard]
description = "キー入力を記録し、エディタでキーボードオーバーレイを追加できるようにします。"
label = "キー入力を記録"
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop-gpui/locales/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ label = "点击时自动缩放"
description = "新建和自动生成的缩放片段所用的缩放倍数。"
label = "默认缩放倍数"

[settings.general.recording.auto_zoom_hold]
description = "每次点击后自动生成的缩放片段保持放大的时长。"
label = "点击后缩放保持时长"

[settings.general.recording.auto_zoom_merge_gap]
description = "合并间隔小于此值的连续点击缩放。设为 0s 则不合并间隔。"
label = "合并相近点击间隔"

[settings.general.recording.capture_keyboard]
description = "记录按键,以便在编辑器中添加键盘按键显示。"
label = "记录键盘按键"
Expand Down
81 changes: 76 additions & 5 deletions apps/desktop-gpui/src/editor_edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2323,10 +2323,50 @@ pub fn clip_trim_end(
// Auto zoom
// ---------------------------------------------------------------------------

pub const DEFAULT_AUTO_ZOOM_HOLD_SECONDS: f64 = 2.5;
pub const DEFAULT_AUTO_ZOOM_MERGE_GAP_SECONDS: f64 = 2.5;

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct AutoZoomTiming {
pub post_padding_ms: f64,
pub merge_gap_ms: f64,
}

impl Default for AutoZoomTiming {
fn default() -> Self {
Self {
post_padding_ms: DEFAULT_AUTO_ZOOM_HOLD_SECONDS * 1000.0,
merge_gap_ms: DEFAULT_AUTO_ZOOM_MERGE_GAP_SECONDS * 1000.0,
}
}
}

impl AutoZoomTiming {
pub fn from_seconds(hold_seconds: f64, merge_gap_seconds: f64) -> Self {
Self {
post_padding_ms: hold_seconds.max(0.1) * 1000.0,
merge_gap_ms: merge_gap_seconds.max(0.0) * 1000.0,
}
}
}
pub fn generate_zoom_segments_for_timeline(
clicks_by_clip: &[Vec<CursorClickEvent>],
timeline: &TimelineConfiguration,
zoom_amount: f64,
) -> Vec<ZoomSegment> {
generate_zoom_segments_for_timeline_with_timing(
clicks_by_clip,
timeline,
zoom_amount,
AutoZoomTiming::default(),
)
}

pub fn generate_zoom_segments_for_timeline_with_timing(
clicks_by_clip: &[Vec<CursorClickEvent>],
timeline: &TimelineConfiguration,
zoom_amount: f64,
timing: AutoZoomTiming,
) -> Vec<ZoomSegment> {
let ordered_clicks: Vec<_> = clicks_by_clip
.iter()
Expand Down Expand Up @@ -2364,7 +2404,12 @@ pub fn generate_zoom_segments_for_timeline(
mapped.push(click);
}
}
generate_zoom_segments_from_clicks(mapped, timeline.duration(), zoom_amount)
generate_zoom_segments_from_clicks_with_timing(
mapped,
timeline.duration(),
zoom_amount,
timing,
)
}

/// `generate_zoom_segments_from_clicks_impl`
Expand All @@ -2375,17 +2420,31 @@ pub fn generate_zoom_segments_for_timeline(
/// clamped inside the recording. The Tauri signature also takes the cursor
/// *moves* and ignores them; this one does not pretend to want them.
pub fn generate_zoom_segments_from_clicks(
clicks: Vec<CursorClickEvent>,
max_duration: f64,
zoom_amount: f64,
) -> Vec<ZoomSegment> {
generate_zoom_segments_from_clicks_with_timing(
clicks,
max_duration,
zoom_amount,
AutoZoomTiming::default(),
)
}

pub fn generate_zoom_segments_from_clicks_with_timing(
mut clicks: Vec<CursorClickEvent>,
max_duration: f64,
zoom_amount: f64,
timing: AutoZoomTiming,
) -> Vec<ZoomSegment> {
const MS_PER_SECOND: f64 = 1000.0;
const START_MIN_MS: f64 = 1.0;
const CLICK_PRE_PADDING_MS: f64 = 300.0;
const CLICK_POST_PADDING_MS: f64 = 2500.0;
const CLICK_END_CLAMP_PADDING_MS: f64 = 800.0;
const TRAILING_CLICK_IGNORE_MS: f64 = 1000.0;
const MERGE_GAP_MS: f64 = 2500.0;
let post_padding_ms = timing.post_padding_ms.max(0.0);
let merge_gap_ms = timing.merge_gap_ms.max(0.0);

if max_duration <= 0.0 {
return Vec::new();
Expand All @@ -2412,7 +2471,7 @@ pub fn generate_zoom_segments_from_clicks(
}

let start = (time_ms - CLICK_PRE_PADDING_MS).max(START_MIN_MS);
let end = (time_ms + CLICK_POST_PADDING_MS).min(end_limit_ms);
let end = (time_ms + post_padding_ms).min(end_limit_ms);

if end > start {
intervals.push((start, end));
Expand All @@ -2428,7 +2487,7 @@ pub fn generate_zoom_segments_from_clicks(
let mut merged: Vec<(f64, f64)> = Vec::new();
for interval in intervals {
if let Some(last) = merged.last_mut()
&& interval.0 <= last.1 + MERGE_GAP_MS
&& interval.0 <= last.1 + merge_gap_ms
{
last.1 = last.1.max(interval.1);
continue;
Expand Down Expand Up @@ -3842,6 +3901,18 @@ mod tests {
assert_eq!(segments[1].end, 12.5);
}

#[test]
fn custom_auto_zoom_timing_respects_hold_duration_and_merge_gap() {
let segments = generate_zoom_segments_from_clicks_with_timing(
vec![click(1_000.), click(2_500.), click(4_200.)],
20.0,
2.0,
AutoZoomTiming::from_seconds(1.0, 0.2),
);
let bounds: Vec<_> = segments.iter().map(|s| (s.start, s.end)).collect();
assert_eq!(bounds, vec![(0.7, 3.5), (3.9, 5.2)]);
}

#[test]
fn no_clicks_or_no_duration_generate_no_zoom_segments() {
assert!(generate_zoom_segments_from_clicks(Vec::new(), 20.0, 2.0).is_empty());
Expand Down
11 changes: 9 additions & 2 deletions apps/desktop-gpui/src/editor_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6283,7 +6283,12 @@ impl EditorWindow {
self.auto_zoom_message = None;
cx.notify();
let path = self.project_path.clone();
let amount = new_zoom_amount();
let settings = crate::store::GeneralSettings::load();
let amount = f64::from(settings.new_zoom_amount());
let timing = edits::AutoZoomTiming::from_seconds(
f64::from(settings.auto_zoom_hold_seconds()),
f64::from(settings.auto_zoom_merge_gap_seconds()),
);
cx.spawn_in(window, async move |this, cx| {
let clicks = cx
.background_executor()
Expand All @@ -6298,7 +6303,9 @@ impl EditorWindow {
.timeline
.as_ref()
.map_or_else(Vec::new, |timeline| {
edits::generate_zoom_segments_for_timeline(&clicks, timeline, amount)
edits::generate_zoom_segments_for_timeline_with_timing(
&clicks, timeline, amount, timing,
)
});
if segments.is_empty() {
tracing::info!("auto zoom produced no segments");
Expand Down
18 changes: 18 additions & 0 deletions apps/desktop-gpui/src/i18n/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,24 @@ fn english_matches_the_literals_it_replaced() {
tr::settings::general::recording::default_zoom::label(),
"Default zoom amount".into(),
),
(
tr::settings::general::recording::auto_zoom_hold::description(),
"How long auto-generated zoom segments stay zoomed in after each click.".into(),
),
(
tr::settings::general::recording::auto_zoom_hold::label(),
"Zoom hold after click".into(),
),
(
tr::settings::general::recording::auto_zoom_merge_gap::description(),
"Merge consecutive click zooms separated by less than this gap. \
Set to 0s to never merge gaps."
.into(),
),
(
tr::settings::general::recording::auto_zoom_merge_gap::label(),
"Merge nearby clicks gap".into(),
),
(
tr::settings::general::recording::capture_keyboard::description(),
"Record key presses so you can add keyboard overlays in the editor.".into(),
Expand Down
Loading