fix: scroll timeline to deep-linked playhead on first load

When a project opens with a ?f=<frame> query parameter, the playhead position
is now visible in the timeline view. Previously, the playhead was positioned
correctly in the UI but the timeline didn't scroll to show it. This triggered
scroll-to-seg-track on first render when playhead > 0 and segments are loaded.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Your Name 2026-06-30 14:06:20 -04:00
parent d91ea6c78a
commit 52c700b843

View file

@ -15,6 +15,7 @@
(defonce body-scroll-el (atom nil)) ; the vertical (tracks) scroll container (defonce body-scroll-el (atom nil)) ; the vertical (tracks) scroll container
(defonce playhead-el (atom nil)) ; the single full-height playhead overlay (defonce playhead-el (atom nil)) ; the single full-height playhead overlay
(defonce played-bar (atom nil)) ; [ann-id bar-idx] last auto-scrolled to during playback (defonce played-bar (atom nil)) ; [ann-id bar-idx] last auto-scrolled to during playback
(defonce scrolled-on-load? (atom nil)) ; did we scroll to deep-linked playhead on load
(defonce play (atom nil)) ; {:ctx :segs :fps :idx} while playing, else nil (defonce play (atom nil)) ; {:ctx :segs :fps :idx} while playing, else nil
(defonce active-insert! (atom nil)) ; the live content-editor's (insert! link) fn (defonce active-insert! (atom nil)) ; the live content-editor's (insert! link) fn
(declare commit-link!) (declare commit-link!)
@ -342,6 +343,10 @@
(r/after-render (r/after-render
(fn [] (fn []
(follow! fps zoom playhead) (follow! fps zoom playhead)
;; first load: if playhead was deep-linked (from query param), scroll to it once
(when (and (nil? @scrolled-on-load?) (> playhead 0) (seq segs))
(reset! scrolled-on-load? true)
(scroll-to-seg-track! segs playhead))
;; clip-following: only while the playhead is actually inside a bar of ;; clip-following: only while the playhead is actually inside a bar of
;; an annotation that opts in (:meta :scroll-to) — scroll each of its ;; an annotation that opts in (:meta :scroll-to) — scroll each of its
;; clips into view as the playhead crosses onto a new bar (discontinuity). ;; clips into view as the playhead crosses onto a new bar (discontinuity).
@ -356,7 +361,8 @@
(when (not= current-bar @played-bar) (when (not= current-bar @played-bar)
(reset! played-bar current-bar) (reset! played-bar current-bar)
(scroll-to-seg-track! segs playhead))))) (scroll-to-seg-track! segs playhead)))))
(reset! played-bar nil)) (do (reset! played-bar nil)
(reset! scrolled-on-load? nil)))
(r/after-render #(position-playhead! fps zoom playhead)) (r/after-render #(position-playhead! fps zoom playhead))
[:div.timeline {:class (when-not @tracks-open? "tracks-collapsed")} [:div.timeline {:class (when-not @tracks-open? "tracks-collapsed")}
[:div.playhead.timeline-playhead {:ref (fn [n] (reset! playhead-el n))} [:div.playhead.timeline-playhead {:ref (fn [n] (reset! playhead-el n))}