From 1a92a103cc638b417ce6dc9cdc759cee05988282 Mon Sep 17 00:00:00 2001 From: Olive Vaughn Date: Sun, 11 Oct 2026 00:07:13 -0400 Subject: [PATCH] Drawing in a lane draws into the drawing it shows With the lane as the target, the brush and the pen made a new cel at the playhead and cut the one showing there short. What is on screen is what you are drawing on, so the shape goes into it, as if that cel were selected; only where the lane shows nothing is a new cel made. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011FLuCjp9kNH6ovwJVXSbq9 --- frontend/src/arthur/events/ui.cljs | 34 ++++++++++++++-------- frontend/test/arthur/events/lane_test.cljs | 23 +++++++++++---- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index d67ce86..5b0ef09 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -705,12 +705,8 @@ (fn [db [_ size]] (assoc-in db [:ui :brush] (-> size js/Math.round (max 1) (min 64))))) (defn new-lane-drawing - "Create the one-frame drawing cel implied by drawing with a lane row active. - - A lane is an insertion surface, so this always makes a new cel at the - playhead. Existing content at that frame is claimed and trimmed by - `overwrite-drawing`. Selecting an existing cel resolves to that cel's ordinary - source symbol before this function is reached, and therefore draws inside it. + "Create the one-frame drawing cel implied by drawing with a lane row active, + where the lane shows nothing at the playhead — see `polygon-landing`. `overwrite-drawing` rather than `append-drawing`, because a gap already has the room. Appending RIPPLES everything after it later by the new clip's @@ -729,17 +725,31 @@ made {:clip (:clip made) :sid sid :path (conj (vec path) cel-id)})))) +(defn- showing + "The id of the clip of lane `sid` that is on screen at the lane's frame `f`, + or nil where the lane shows nothing." + [clip sid f] + (some (fn [[id n]] + (when-let [[lo hi] (node/placed-span n)] + (when (and (node/source n) (<= lo f) (< f hi)) id))) + (get-in clip [:symbols sid :nodes]))) + (defn polygon-landing "Choose the document and row path a finished polygon is drawn into. - A resolved lane always gets a new drawing cel. A selected cel resolves to its - source symbol instead, so drawing there adds a child to that existing cel." + DRAWING IN A LANE DRAWS INTO WHAT IT SHOWS. With the lane as the target, the + drawing on screen at the playhead is what you are drawing on, so the shape + goes into it — exactly as if that cel were selected. Only where the lane shows + nothing is a new cel made; a new drawing over an old one is K's job, and ⇧K's, + not a side effect of the brush." [clip st db] (let [into (creation/target clip st (get-in db [:ui :open]) - (get-in db [:ui :selection]) (editing-frame db clip))] - (if (= :lane (:kind into)) - (assoc (new-lane-drawing clip into) :lane? true) - {:clip clip :sid (:sid into) :path (:path into) :lane? false}))) + (get-in db [:ui :selection]) (editing-frame db clip)) + cel (when (= :lane (:kind into)) (showing clip (:sid into) (:frame into)))] + (cond + cel {:clip clip :path (conj (vec (:path into)) cel) :lane? false} + (= :lane (:kind into)) (assoc (new-lane-drawing clip into) :lane? true) + :else {:clip clip :sid (:sid into) :path (:path into) :lane? false}))) (defn beginning-polygon "Enter polygon mode, first materializing a new drawing at the playhead when diff --git a/frontend/test/arthur/events/lane_test.cljs b/frontend/test/arthur/events/lane_test.cljs index 37e5da8..f7a9154 100644 --- a/frontend/test/arthur/events/lane_test.cljs +++ b/frontend/test/arthur/events/lane_test.cljs @@ -370,10 +370,14 @@ (deftest polygon-landing-obeys-the-destination-symbol-mode (let [lane (fixture/document) + gap (update-in lane [:symbols :main :nodes] dissoc :b) ordinary (update-in lane [:symbols :main] dissoc :display) db {:ui {:open :main :selection [:node :main :plate [:plate]]} :playback {:frame 5}}] - (is (true? (:lane? (ui/polygon-landing lane {} db)))) + (is (= {:lane? false :path [:b]} (select-keys (ui/polygon-landing lane {} db) [:lane? :path])) + "a lane draws into the cel it shows at the playhead") + (is (true? (:lane? (ui/polygon-landing gap {} db))) + "and makes a new one only where it shows nothing") (is (false? (:lane? (ui/polygon-landing ordinary {} db)))))) (deftest beginning-a-polygon-does-not-invent-a-lane @@ -389,18 +393,27 @@ (is (nil? (get-in saved [:symbols :main :display]))) (is (nil? (get-in (store/entry (:clip/current after)) [:history :done]))))) -(deftest drawing-with-the-lane-row-active-creates-a-new-cel +(deftest drawing-with-the-lane-row-active-draws-into-what-it-shows (let [doc (fixture/document) - id (store/install! {:clip doc :store {}} "draw-new-lane-cel") + id (store/install! {:clip doc :store {}} "draw-into-lane-cel") db {:clip/current id :paint/revision 0 :ui {:open :main :selection [:node :main nil []]} :playback {:frame 1}} + after (ui/beginning-polygon db)] + (is (= doc (:clip (store/entry id))) "no cel is made over the one showing") + (is (= [] (get-in after [:ui :draft]))))) + +(deftest drawing-with-the-lane-row-active-in-a-gap-creates-a-new-cel + (let [doc (update-in (fixture/document) [:symbols :main :nodes] dissoc :b) + id (store/install! {:clip doc :store {}} "draw-new-lane-cel") + db {:clip/current id :paint/revision 0 + :ui {:open :main :selection [:node :main nil []]} + :playback {:frame 5}} after (ui/beginning-polygon db) [_ sid cel-id] (get-in after [:ui :selection]) saved (:clip (store/entry id))] (is (= :main sid)) - (is (not= :a cel-id) "the occupied cel is not reused") - (is (= [1 2] (node/placed-span (get-in saved [:symbols sid :nodes cel-id])))) + (is (= [5 6] (node/placed-span (get-in saved [:symbols sid :nodes cel-id])))) (is (= 1 (clip/frames saved (node/source (get-in saved [:symbols sid :nodes cel-id]))))) (is (= [] (get-in after [:ui :draft])))))