Give a remap shape something to drag it by

A remap draws light rather than colour, so `pick/hit-op` let a click go THROUGH
it to what it lights, and `op-bounds` left it out of a marquee's reach. Both of
those rules are about getting PAST a shape, and neither has anything to say
about the shape you have in your hands — but the stage's move gesture IS that
hit-test, while `handles` hangs its box and corners off `pick/bounds-of`, which
reads the node's points and knows nothing about colour.

So a remap shape got a full set of handles over a shape that answered no point
on the stage at all. The first press on it started a marquee, the marquee
selected nothing, and the selection a timeline row had just given it was thrown
away: selectable in the timeline, and then neither movable nor resizable, with
the handles sitting right there. A knockout was the same bug for the same
reason, and both of them read as handles that do not work.

`hit-op` now takes what is selected, and what is selected is never
click-through. That is `choose`'s own rule — a click inside what is selected
keeps it, so a deep selection can be dragged — reaching one step further down;
clicking a remap you have NOT selected still goes through to what it lights,
which is the point of it. `op-bounds` keeps a hole's and a light's bounds like
anything else, so a marquee reaches one without going to the timeline for it.

`browser/remap.mjs` asserts it as `peg.mjs` does, with real pointer events
through the handles, and for the same reason: every assertion about the maths
passed throughout.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Your Name 2026-10-05 22:22:52 -04:00
parent 39c436584b
commit 2e021a13eb
5 changed files with 239 additions and 25 deletions

View file

@ -63,8 +63,13 @@
(and (<= 0 u) (< u w) (<= 0 v) (< v h))))
false))
(defn- op-bounds [{:keys [kind pts n cx cy r size knock lut] :as op}]
(case (when-not (or knock lut) kind)
;; A HOLE AND A LIGHT HAVE BOUNDS LIKE ANYTHING ELSE. A knockout and a remap
;; were both left out of this, which is the rule `hit-op` plays by — a click
;; goes through them to what shows under — carried over to a gesture it is wrong
;; for: a marquee asks what is INSIDE it, not what a point lands on, and leaving
;; them out meant the only way to select one anywhere was its timeline row.
(defn- op-bounds [{:keys [kind pts n cx cy r size] :as op}]
(case kind
:trace (let [cs (trace-corners op)]
[(apply min (map first cs)) (apply min (map second cs))
(apply max (map first cs)) (apply max (map second cs))])
@ -98,24 +103,40 @@
"The topmost op in `ops`, in draw order, that SHOWS at stage point `[x y]`, or
nil. A knockout is never hit: it is a hole, and a click in it is a click on
whatever shows through — so it hides the ops beneath it in its own symbol, of
the colour it clears."
[ops [x y]]
(:op (reduce (fn [holes op]
(cond
;; A remap is light on what is under it, not a thing.
(or (:lut op) (not (on? op x y))) holes
(:knock op) (conj holes [(pop (path-of op)) (:knock op)])
(some (fn [[in k]] (and (prefix? in (path-of op))
(or (neg? k) (== k (:color op)))))
holes) holes
:else (reduced {:op op})))
[] (let [{traces true drawn false} (group-by #(= :trace (:kind %)) (rseq (vec ops)))]
(concat drawn traces)))))
the colour it clears. A remap is the same kind of thing the other way up: it is
light on what is under it, so a click goes through it to what it lights.
EXCEPT WHAT IS ALREADY SELECTED, which `selected` is the row path of. Both of
those rules are about reaching PAST a shape, and neither has anything to say
about the shape you have in your hands: a selected remap or knockout answered
no point on the stage at all, so there was nothing to drag it by — the stage's
move gesture is this hit-test on the ops, and `handles` draws a box round
bounds that nothing could then grab. The first press on one started a marquee
instead, which selected nothing and so threw the selection away, and that is
the whole of why a palette swapper could be selected from a timeline row and
then neither moved nor resized. The ordinary depth rule — a click inside what
is selected keeps it, so a deep selection can be dragged — is `choose`'s, and
this is the same rule reaching one step further down."
([ops point] (hit-op ops point nil))
([ops [x y] selected]
(:op (reduce (fn [holes op]
(cond
(not (on? op x y)) holes
(and selected (prefix? selected (path-of op))) (reduced {:op op})
(:lut op) holes
(:knock op) (conj holes [(pop (path-of op)) (:knock op)])
(some (fn [[in k]] (and (prefix? in (path-of op))
(or (neg? k) (== k (:color op)))))
holes) holes
:else (reduced {:op op})))
[] (let [{traces true drawn false} (group-by #(= :trace (:kind %)) (rseq (vec ops)))]
(concat drawn traces))))))
(defn hit
"The row path of the topmost op that shows at stage point `[x y]`, or nil."
[ops point]
(some-> (hit-op ops point) path-of))
"The row path of the topmost op that shows at stage point `[x y]`, or nil.
`selected` is what is selected now, which a light or a hole does not hide."
([ops point] (hit ops point nil))
([ops point selected] (some-> (hit-op ops point selected) path-of)))
(defn choose
"The row path a click on `hit` selects, with `selected` the one selected now."

View file

@ -220,9 +220,12 @@
"The topmost row path drawn at stage point `point` on the frame last painted,
or nil. Read off the ops the canvas was drawn from, so a click picks exactly
what is seen: their point buffers stay good until the next paint, and a
pointer event is handled between two."
[point]
(pick/hit (:ops @state) point))
pointer event is handled between two.
`selected` is the row path selected now, which a light or a hole it belongs to
does not hide from this: see `pick/hit-op`."
([point] (at point nil))
([point selected] (pick/hit (:ops @state) point selected)))
(defn hit-op
"The topmost op that shows at `point`, as `at` picks it: what the eraser

View file

@ -636,7 +636,10 @@
(do (.setPointerCapture svg (.-pointerId event))
(stroke-begin! ctx tool p size tone event))
(let [path (pick/choose selected (player/at p) (.-altKey event))]
;; WITH THE SELECTION, so a shape the hit-test treats as light
;; or as a hole — a palette swapper, a knockout — can be
;; dragged by the one you are holding. See `pick/hit-op`.
(let [path (pick/choose selected (player/at p selected) (.-altKey event))]
(when (and path (not (.-shiftKey event)))
(reset! selection-anchor {:clip-id clip-id :open (:open ctx) :path path}))
(cond
@ -672,7 +675,7 @@
:on-double-click (fn [^js event]
(when (= :select tool)
(let [p (xy (.-currentTarget event) event w h)
hit (player/at p)
hit (player/at p selected)
path (pick/deeper selected hit)]
(cond
(not= path selected) (select! ctx path)