FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
fix(timeline): HomeとEndで再生位置を常に表示する (#1188)
Ikki Nishihara2ad63fd7ff5b
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 77833a1b7..04d79ac34 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -567,6 +567,9 @@ pub fn invoke(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, mut params:if let Err(e) = &r {app.ui.status = e.clone();}+ if r.is_ok() && matches!(id, "playhead.start" | "playhead.end") {+ crate::panels::timeline::reveal_playhead(app, ctx);+ }if r.is_ok() && matches!(id, "edit.copy" | "edit.cut") {remember_stale_clipboard_media(app);put_clip_names_on_system_clipboard(app, ctx);diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex 2079277b2..2351776cb 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -258,6 +258,18 @@ pub fn scroll_to_reveal(ph: f64, scroll: f64, pps: f64, width: f64) -> Option<f6(px < 0.0 || px > width).then(|| (ph - width * 0.05 / pps).max(0.0))}+/// Explicit navigation reveals the playhead even when its time has not changed (#1188).+pub(crate) fn reveal_playhead(app: &mut FilmcraftApp, ctx: &egui::Context) {+ let ph = app.session.playhead().seconds();+ let v = &mut app.ui.timeline;+ if let Some(scroll) = scroll_to_reveal(ph, v.target_scroll, v.target_pps, f64::from(app.last_timeline_width)) {+ v.scroll = scroll;+ v.target_scroll = scroll;+ app.tl.zoom_anchor = None;+ ctx.request_repaint();+ }+}+/// Zoom about a time (keeps it under the same screen x).pub fn zoom_about(v: &mut TimelineView, factor: f64, anchor_secs: f64, width: f32) {let old = v.target_pps;diff --git a/crates/ui-egui/tests/timeline_scroll_ui.rs b/crates/ui-egui/tests/timeline_scroll_ui.rsindex c20a9c23d..7587ef14a 100644--- a/crates/ui-egui/tests/timeline_scroll_ui.rs+++ b/crates/ui-egui/tests/timeline_scroll_ui.rs@@ -301,3 +301,44 @@ fn home_and_end_bring_the_playhead_into_view() {let width = 1600.0 / v.pps;assert!(v.target_scroll > 3.0 && v.target_scroll <= end && end - v.target_scroll < width, "End shows the playhead: scroll {} end {end}", v.target_scroll);}++fn repeated_endpoint_navigation_reveals_the_same_playhead(use_keys: bool) {+ let mut d = Driver::demo();+ let project = d.app().session.project.clone();+ let undo = d.app().session.history.undo.len();+ for (command, key, manual_scroll) in [("playhead.start", "Home", 5.0), ("playhead.end", "End", 0.0)] {+ d.exec(command, json!({}));+ d.frames(3);+ let playhead = d.app().session.playhead();+ d.ok("ui.set", json!({"timeline": {"pps": 400.0, "scroll": manual_scroll}}));+ d.frames(3);+ assert_eq!(d.view().0, manual_scroll, "manual browsing is allowed while stopped");+ if use_keys {+ d.ok("ui.key", json!({"key": key}));+ } else {+ d.exec(command, json!({}));+ }+ d.frames(3);+ let (scroll, pps, ..) = d.view();+ let x = (playhead.seconds() - scroll) * pps;+ let width = f64::from(d.app().last_timeline_width);+ assert!((0.0..=width).contains(&x), "{key} reveals an unchanged playhead: x={x}, width={width}, scroll={scroll}");+ assert_eq!(d.app().session.playhead(), playhead);+ assert!(std::sync::Arc::ptr_eq(&project, &d.app().session.project));+ assert_eq!(d.app().session.history.undo.len(), undo);+ // An explicit navigation must not turn later manual browsing into continuous following.+ d.ok("ui.set", json!({"timeline": {"scroll": manual_scroll}}));+ d.frames(3);+ assert_eq!(d.view().0, manual_scroll);+ }+}++#[test]+fn repeated_home_and_end_keys_reveal_a_playhead_already_at_the_endpoint() {+ repeated_endpoint_navigation_reveals_the_same_playhead(true);+}++#[test]+fn repeated_start_and_end_commands_reveal_a_playhead_already_at_the_endpoint() {+ repeated_endpoint_navigation_reveals_the_same_playhead(false);+}