fix: reliable playhead-driven pane scroll to the active annotation
Rewrite commentary-scroll as a lifecycle component that scrolls in component-did-update via scrollIntoView (offsetParent-agnostic, so it works for nested cards too), replacing the fragile after-render + manual offsetTop math. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
28bdac1142
commit
f6e887c14d
1 changed files with 13 additions and 9 deletions
|
|
@ -1095,15 +1095,19 @@
|
|||
;; Renders nothing: owns the active-annotation subscription and scrolls the active
|
||||
;; card into view, so `commentary` itself no longer re-renders on every crossing.
|
||||
(defn- commentary-scroll [el]
|
||||
(let [active @(rf/subscribe [::subs/active-annotation])]
|
||||
(r/after-render
|
||||
(fn [] (when-let [c @el]
|
||||
(when-let [node (and active (.querySelector c (str "#ann-" (name active))))]
|
||||
;; scrollIntoView (not manual offsetTop math): a nested card's
|
||||
;; offsetParent is its parent .ann (position:relative), so offsetTop
|
||||
;; would be measured inside the parent, not the scroll container.
|
||||
(.scrollIntoView node #js {:block "center" :behavior "smooth"})))))
|
||||
nil))
|
||||
;; Form-3 so the scroll runs in component-did-update — reliably after the DOM is
|
||||
;; committed on every active-annotation change — and via scrollIntoView, which
|
||||
;; (unlike offsetTop math) is correct even when the active card is nested.
|
||||
(letfn [(scroll! [& _]
|
||||
(let [active @(rf/subscribe [::subs/active-annotation])]
|
||||
(when-let [c @el]
|
||||
(when-let [node (and active (.querySelector c (str "#ann-" (name active))))]
|
||||
(.scrollIntoView node #js {:block "center" :behavior "smooth"})))))]
|
||||
(r/create-class
|
||||
{:display-name "commentary-scroll"
|
||||
:component-did-mount scroll!
|
||||
:component-did-update scroll!
|
||||
:reagent-render (fn [_] @(rf/subscribe [::subs/active-annotation]) nil)})))
|
||||
|
||||
(defn commentary []
|
||||
(let [el (atom nil) open (r/atom nil)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue