On a phone one finger draws and two move the view

A tap focused the overlay, which is the whole work area, and the phone
scrolled to show its corner: the stage jumped off screen and every point
after it landed sideways. Focus without scrolling, here and on the
timeline. One finger never scrolls the stage; only the first pointer
feeds a stroke; a second finger drops it and pans by the fingers' middle
and zooms by their spread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011FLuCjp9kNH6ovwJVXSbq9
This commit is contained in:
Olive Vaughn 2026-10-10 23:56:35 -04:00
parent b40564ad97
commit 86f2d96762
2 changed files with 77 additions and 15 deletions

View file

@ -601,6 +601,14 @@
[:circle {:class (str "first" (when (and hover (closes? draft hover)) " closing"))
:cx fx :cy fy :r 1.8}]])))
(defn- abandon!
"Whatever a pointer was doing on the stage, dropped rather than finished: the
browser took the pointer back, or a second finger came down to move the view."
[]
(reset! dragging nil) (reset! marquee nil)
(reset! painting nil) (player/stroke! nil)
(let-go! false))
(defn- overlay [w h zoom [x0 y0 x1 y1]]
(let [tool @(rf/subscribe [::sub/tool])
draft @(rf/subscribe [::sub/draft])
@ -634,10 +642,16 @@
:view-box (str x0 " " y0 " " (- x1 x0) " " (- y1 y0))
:tab-index -1
:on-pointer-down
;; ONE POINTER DRAWS: the first finger down. A second is the view's —
;; see `navigation` — and fed into a stroke it zigzags between the two.
(fn [^js event]
(when (.-isPrimary event)
(let [svg (.-currentTarget event)
p (xy svg event w h)]
(.focus svg)
;; Without scrolling it into view: the overlay is the whole work
;; area, and a phone scrolled to show its corner, which threw the
;; stage off screen on a tap and every point after it sideways.
(.focus svg #js {:preventScroll true})
(case tool
:pen
(let [q (snapped draft (stage-point event w h) event)
@ -688,7 +702,7 @@
(.setPointerCapture svg (.-pointerId event))
(if (and (> (count placements) 1) (contains? selected-paths path))
(begin-many! ctx :move placements p)
(begin! ctx :move path p)))))))
(begin! ctx :move path p))))))))
:on-double-click (fn [^js event]
(when (= :select tool)
(let [p (xy (.-currentTarget event) event w h)
@ -706,6 +720,7 @@
:on-pointer-leave (fn [_] (reset! pointer nil))
:on-pointer-move
(fn [^js event]
(when (.-isPrimary event)
(let [p (xy (.-currentTarget event) event w h)]
(reset! pointer p)
(cond
@ -719,8 +734,9 @@
(when (not= q hover) (rf/dispatch [::ui/hover q])))
@repivot (swap! repivot assoc :p p)
@marquee (swap! marquee assoc :p p)
@gesture (drag! p event))))
:on-pointer-up (fn [_]
@gesture (drag! p event)))))
:on-pointer-up (fn [^js event]
(when (.-isPrimary event)
(reset! dragging nil)
(stroke-end!)
;; One edit, at the end: see `::ui/repivot`.
@ -735,11 +751,8 @@
old (if more? selections [])]
(reset! marquee nil)
(rf/dispatch [::ui/select-many (into old addresses)]))
(let-go! true)))
:on-pointer-cancel (fn [_]
(reset! dragging nil) (reset! marquee nil)
(reset! painting nil) (player/stroke! nil)
(let-go! false))}
(let-go! true))))
:on-pointer-cancel (fn [_] (abandon!))}
[ghost]
(when (seq selected-pts)
[:polygon.selected-paint-outline
@ -766,6 +779,18 @@
(defonce pinch-start-zoom (atom nil))
;; Two fingers on the stage: `{:zoom :spread :at}` as they came down, and where
;; their middle was last.
(defonce ^:private two (atom nil))
(defn- middle [^js touches]
(let [a (aget touches 0) b (aget touches 1)]
[(/ (+ (.-clientX a) (.-clientX b)) 2) (/ (+ (.-clientY a) (.-clientY b)) 2)]))
(defn- apart [^js touches]
(let [a (aget touches 0) b (aget touches 1)]
(js/Math.hypot (- (.-clientX a) (.-clientX b)) (- (.-clientY a) (.-clientY b)))))
(defn- navigation []
{:title "Two-finger scroll to pan · Pinch or ⌘/Ctrl-wheel to zoom · Space-drag or middle-drag to pan"
;; The picture is what is on screen, so moving or resizing the view paints
@ -790,11 +815,48 @@
(do
(set! (.-scrollLeft el) (+ (.-scrollLeft el) dx))
(set! (.-scrollTop el) (+ (.-scrollTop el) dy))))))))
;; Safari exposes pinch as GestureEvents, with cumulative scale.
;; ON A PHONE ONE FINGER IS THE PEN AND TWO ARE THE VIEW. Nothing on
;; the stage scrolls under one finger — `touch-action` says so, and
;; is not trusted on an SVG in iOS — and two pan by their middle and
;; zoom by their spread, with whatever the first had begun dropped.
;; Properties rather than listeners, as `onwheel` is: this ref runs on
;; every render. Not passive, being on an element, so they can stop
;; the page.
(set! (.-ontouchstart el)
(fn [^js e]
(let [ts (.-touches e)]
(when (<= 2 (.-length ts))
(.preventDefault e)
(abandon!)
(reset! two {:zoom @(rf/subscribe [::layout/zoom :stage])
:spread (apart ts) :at (middle ts)})))))
(set! (.-ontouchmove el)
(fn [^js e]
(let [ts (.-touches e)]
(cond
(and @two (<= 2 (.-length ts)))
(let [{:keys [zoom at] s0 :spread} @two
[x y :as m] (middle ts)
z (* zoom (/ (apart ts) (max 1 s0)))]
(.preventDefault e)
(if (< (js/Math.abs (- 1 (/ z @(rf/subscribe [::layout/zoom :stage])))) 0.02)
(do (set! (.-scrollLeft el) (+ (.-scrollLeft el) (- (first at) x)))
(set! (.-scrollTop el) (+ (.-scrollTop el) (- (second at) y))))
(layout/zoom-at! el x y z))
(swap! two assoc :at m))
(.closest (.-target e) ".paint-overlay")
(.preventDefault e)))))
(set! (.-ontouchend el)
(fn [^js e] (when (< (.-length (.-touches e)) 2) (reset! two nil))))
(set! (.-ontouchcancel el) (.-ontouchend el))
;; Safari exposes pinch as GestureEvents, with cumulative scale. On a
;; phone the touches above have it already.
(set! (.-ongesturestart el)
(fn [e]
(.preventDefault e)
(reset! pinch-start-zoom @(rf/subscribe [::layout/zoom :stage]))))
(when-not @two
(reset! pinch-start-zoom @(rf/subscribe [::layout/zoom :stage])))))
(set! (.-ongesturechange el)
(fn [e]
(.preventDefault e)

View file

@ -953,7 +953,7 @@
(cond
(= k "Escape") (reset! chosen [])
(#{"Delete" "Backspace"} k)
(do (.focus (.closest (.-currentTarget e) "section.time"))
(do (.focus (.closest (.-currentTarget e) "section.time") #js {:preventScroll true})
(rf/dispatch [::ui/edit-keyframes @chosen nil]) (reset! chosen []))
:else (let [df (* (if (= k "ArrowLeft") -1 1) (if (.-shiftKey e) 10 1))
xs @chosen]
@ -962,7 +962,7 @@
:on-pointer-down
(fn [e]
(.stopPropagation e)
(.focus (.-currentTarget e))
(.focus (.-currentTarget e) #js {:preventScroll true})
(let [ids (set (map keyframes/identity-of items))
selected? (some (:ids @key-state) (map keyframes/identity-of items))]
(cond
@ -1154,7 +1154,7 @@
begin! (fn [^js e actual-path gesture-kind actual-select other drag]
(let [track (.closest (.-currentTarget e) ".tl-track")]
(.stopPropagation e)
(.focus track)
(.focus track #js {:preventScroll true})
;; SELECTING WAITS FOR THE RELEASE. Selecting on the press
;; changed what the timeline was showing before the gesture
;; had said anything: an expanded lane follows the
@ -1643,7 +1643,7 @@
(.closest (.-target e) ".tl-track.automation")
(not (.closest (.-target e) "button, .movable, .unmapped, .tl-edge")))
(.stopPropagation e) (.preventDefault e)
(.focus (.-currentTarget e))
(.focus (.-currentTarget e) #js {:preventScroll true})
(reset! marquee {:x (.-clientX e) :y (.-clientY e)
:hits (let [container (.-currentTarget e)]
(vec (mapcat