diff --git a/frontend/src/arthur/domain/nest.cljs b/frontend/src/arthur/domain/nest.cljs index c6f084c..f35b775 100644 --- a/frontend/src/arthur/domain/nest.cljs +++ b/frontend/src/arthur/domain/nest.cljs @@ -498,7 +498,9 @@ (span/claim clip (:sid here) moved id :grow-symbol (random-uuid)))))) (defn slide-many - "Move a selection simultaneously. Lane collisions refuse the entire edit." + "Move a selection simultaneously: `slide`, for all of it at once. What it + lands on is claimed as `slide` claims it; among themselves the moved nodes + keep their places." [document open paths df] (let [paths (vec (distinct (filter seq paths))) entries (mapv (fn [path] @@ -528,9 +530,10 @@ {} roots)] (reduce (fn [result [sid changed]] (if (:refused result) (reduced result) - (span/finish (:clip result) sid - (merge (get-in (:clip result) [:symbols sid :nodes]) changed) - nil :grow-symbol))) + (span/claim-each (:clip result) sid + (merge (get-in (:clip result) [:symbols sid :nodes]) changed) + (update-vals changed (fn [_] (random-uuid))) + :grow-symbol))) {:clip document} changes))))) (defn resize-out @@ -566,6 +569,19 @@ :else (span/resize-in clip sid id (dragged here nodes id (first (node/placed-span n)) df))))) +(defn resize-many + "Move the `kind` edge, `:in` or `:out`, of every node at `paths` by `df` + frames of `open`: each one's own edit, in turn, so each claims what it claims + alone. One eaten by an earlier one has no edge left to move." + [clip open paths kind df ripple?] + (reduce (fn [result path] + (let [c (:clip result)] + (cond + (nil? (get-in c [:symbols (:sid (down c open (pop path))) :nodes (peek path)])) result + (= :out kind) (let [r (resize-out c open path df ripple?)] (if (:refused r) (reduced r) r)) + :else (let [r (resize-in c open path df)] (if (:refused r) (reduced r) r))))) + {:clip clip} (distinct paths))) + (defn roll "Move the shared boundary at `right-path` and the adjacent `left-path`." [clip open left-path right-path df] @@ -583,6 +599,17 @@ (span/roll clip sid left-id right-id (dragged here nodes right-id (first (node/placed-span right)) df))))) +(defn drag + "What a timeline gesture does to `clip`: `kind` is the handle — `:slide` the + body, `:in` and `:out` an edge, `:roll` a cut — and `paths` the selection it + carries when there is one." + [clip open {:keys [path df kind ripple? other paths]}] + (case kind + :out (if (seq paths) (resize-many clip open paths :out df ripple?) (resize-out clip open path df ripple?)) + :in (if (seq paths) (resize-many clip open paths :in df false) (resize-in clip open path df)) + :roll (roll clip open other path df) + (if (seq paths) (slide-many clip open paths df) (slide clip open path df)))) + (defn restack "Put the node at row path `from` just in front of the one at `to` when `front?`, or just behind it — side by side in one symbol, as the timeline lists diff --git a/frontend/src/arthur/domain/span.cljs b/frontend/src/arthur/domain/span.cljs index 2863b6d..2636897 100644 --- a/frontend/src/arthur/domain/span.cljs +++ b/frontend/src/arthur/domain/span.cljs @@ -144,6 +144,41 @@ [n which f] (assoc-in n [:span (case which :in 0 :out 1)] (local n f))) +(defn- eaten + "`nodes` with lane clip `id`'s interval taken from every clip not in `keep`: + those it covers are removed and those crossing an edge trimmed. A clip crossing + both edges is split, and its remainder is `remainder-id`. Nil where that split + has no free id." + [nodes id keep remainder-id] + (let [[a b] (node/placed-span (get nodes id)) + others (remove #(contains? keep (:id %)) (symbol/children nodes)) + spanning (some #(let [[lo hi] (node/placed-span %)] (and (< lo a) (> hi b))) others)] + (when-not (and spanning (or (nil? remainder-id) (contains? nodes remainder-id))) + (reduce + (fn [ns other] + (let [oid (:id other) + [lo hi] (node/placed-span other)] + (cond + (or (<= hi a) (>= lo b)) ns + (and (< lo a) (> hi b)) + (-> ns + (assoc oid (edged other :out a)) + (assoc remainder-id + (assoc (edged other :in b) :id remainder-id + :z (str "a-" remainder-id)))) + (and (>= lo a) (<= hi b)) (dissoc ns oid) + (< lo a) (assoc ns oid (edged other :out a)) + :else (assoc ns oid (edged other :in b))))) + nodes others)))) + +(defn- lane-child? [clip sid nodes id] + (let [n (get nodes id)] + (and (symbol/lane? (clip/symbol clip sid)) + n (nil? (:parent n)) (node/placed-span n)))) + +(def ^:private split-refusal + {:refused "claiming time inside one clip needs a free ID for its remainder"}) + (defn claim "Commit proposed `nodes`, with `id` claiming its interval in lane mode. @@ -153,37 +188,24 @@ edge are trimmed. A clip crossing both edges is split and therefore needs a caller-supplied `remainder-id`." [clip sid nodes id extent remainder-id] - (let [n (get nodes id) - lane-child? (and (symbol/lane? (clip/symbol clip sid)) - n (nil? (:parent n)) (node/placed-span n))] - (if-not lane-child? - (finish clip sid nodes id extent) - (let [[a b] (node/placed-span n) - others (remove #(= id (:id %)) (symbol/children nodes)) - spanning (first (filter #(let [[lo hi] (node/placed-span %)] - (and (< lo a) (> hi b))) - others))] - (if (and spanning (or (nil? remainder-id) (contains? nodes remainder-id))) - {:refused "claiming time inside one clip needs a free ID for its remainder"} - (finish - clip sid - (reduce - (fn [ns other] - (let [oid (:id other) - [lo hi] (node/placed-span other)] - (cond - (or (<= hi a) (>= lo b)) ns - (and (< lo a) (> hi b)) - (-> ns - (assoc oid (edged other :out a)) - (assoc remainder-id - (assoc (edged other :in b) :id remainder-id - :z (str "a-" remainder-id)))) - (and (>= lo a) (<= hi b)) (dissoc ns oid) - (< lo a) (assoc ns oid (edged other :out a)) - :else (assoc ns oid (edged other :in b))))) - nodes others) - id extent)))))) + (if-not (lane-child? clip sid nodes id) + (finish clip sid nodes id extent) + (if-let [ns (eaten nodes id #{id} remainder-id)] + (finish clip sid ns id extent) + split-refusal))) + +(defn claim-each + "`claim` for clips edited together, `remainders` mapping each one's id to a + free id for a split. Each takes its interval from the clips that are NOT among + them; among themselves they keep the places the edit gave them." + [clip sid nodes remainders extent] + (let [keep (set (keys remainders)) + ns (reduce (fn [ns [id remainder-id]] + (if (lane-child? clip sid ns id) + (or (eaten ns id keep remainder-id) (reduced nil)) + ns)) + nodes remainders)] + (if ns (finish clip sid ns nil extent) split-refusal))) (defn host-frame "Symbol frame `f` as a frame of the space node `id` is POSITIONED in — its diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index c7093a8..1954534 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -1380,11 +1380,8 @@ (let [db (update db :ui dissoc :sliding) clip (:clip (store/entry (:clip/current db))) open (or owner (get-in db [:ui :open])) - r (case kind - :out (nest/resize-out clip open path df ripple?) - :in (nest/resize-in clip open path df) - :roll (nest/roll clip open other path df) - (if (seq paths) (nest/slide-many clip open paths df) (nest/slide clip open path df)))] + r (nest/drag clip open {:path path :df df :kind kind :ripple? ripple? + :other other :paths paths})] (cond (zero? df) db (:refused r) (refused db (:refused r)) @@ -1476,45 +1473,60 @@ (when (js/confirm message) (rf/dispatch then)))) (rf/reg-event-fx - ::delete-symbol - ;; Out of the library, with its placements; see `nest/delete-symbol`. Its tab - ;; closes, and if it was on screen the root takes its place. + ::delete-symbols + ;; Out of the library, with their placements; see `nest/delete-symbol`. Their + ;; tabs close, and if one was on screen the root takes its place. ;; - ;; ASKED FIRST WHEN IT IS PLACED, because then the delete reaches past the row - ;; you pointed at, into every symbol that uses it. One placed nowhere goes - ;; without a question; undo is there either way. - (fn [{:keys [db]} [_ sid sure?]] + ;; ASKED FIRST WHEN ANY IS PLACED, because then the delete reaches past the + ;; rows you pointed at, into every symbol that uses them. Ones placed nowhere + ;; go without a question; undo is there either way. + (fn [{:keys [db]} [_ sids sure?]] (let [clip (:clip (store/entry (:clip/current db))) - {gone :clip why :refused} (nest/delete-symbol clip sid) - uses (clip/uses clip sid)] + sids (vec (distinct sids)) + {gone :clip why :refused} (reduce (fn [r sid] + (let [r (nest/delete-symbol (:clip r) sid)] + (if (:refused r) (reduced r) r))) + {:clip clip} sids) + gone? (set sids) + ;; Uses from outside what is being deleted: those are what reach past. + placed (for [sid sids + :let [owners (remove gone? (clip/owners clip sid))] + :when (seq owners)] + [sid owners])] (cond why {:db (refused db why)} - (and (pos? uses) (not sure?)) - {::confirm {:message (str "Delete " (clip/symbol-name clip sid) "? It is used " - (if (= 1 uses) "once" (str uses " times")) ", in " - (str/join ", " (map #(clip/symbol-name clip %) - (clip/owners clip sid))) - ", and every use of it goes too.") - :then [::delete-symbol sid true]}} + (and (seq placed) (not sure?)) + {::confirm {:message (str "Delete " + (if (= 1 (count sids)) + (clip/symbol-name clip (first sids)) + (str (count sids) " symbols")) + "? " + (str/join "; " (for [[sid owners] placed] + (str (clip/symbol-name clip sid) " is used in " + (str/join ", " (map #(clip/symbol-name clip %) owners))))) + ", and every use goes too.") + :then [::delete-symbols sids true]}} :else (cond-> {:db (-> db (edit/transaction (constantly gone)) - (update-in [:ui :tabs] #(vec (remove #{sid} %))) + (update-in [:ui :tabs] #(vec (remove gone? %))) (update :ui (fn [ui] - (cond-> ui - (= [:symbol sid] (:selection ui)) - (assoc :selection nil :selections [])))))} - (= sid (get-in db [:ui :open])) + (let [left (vec (remove #(and (= :symbol (first %)) (gone? (second %))) + (:selections ui)))] + (assoc ui :selections left + :selection (when (some #{(:selection ui)} left) + (:selection ui)))))))} + (gone? (get-in db [:ui :open])) (assoc :dispatch [::playback/open-symbol (clip/opens-on gone)])))))) (rf/reg-event-fx ::delete-selected ;; Backspace while drawing takes the last point back, as in Illustrator; on - ;; the pen, with a point of the selected shape picked, it takes that point. A - ;; symbol picked in the pool is deleted from the library. + ;; the pen, with a point of the selected shape picked, it takes that point. + ;; Symbols picked in the pool are deleted from the library. (fn [{:keys [db]} _] (let [[vsid vid i] (get-in db [:ui :vertex]) primary (get-in db [:ui :selection])] @@ -1526,7 +1538,8 @@ {:db (deleting-vertex db vsid vid i)} (= :symbol (first primary)) - {:dispatch [::delete-symbol (second primary)]} + {:dispatch [::delete-symbols (keep (fn [[kind sid]] (when (= :symbol kind) sid)) + (cons primary (get-in db [:ui :selections])))]} :else (let [many (vec (get-in db [:ui :selections])) diff --git a/frontend/src/arthur/subs/render.cljs b/frontend/src/arthur/subs/render.cljs index be13ff6..aad177f 100644 --- a/frontend/src/arthur/subs/render.cljs +++ b/frontend/src/arthur/subs/render.cljs @@ -43,13 +43,8 @@ ;; lets go, so the stage and the rows follow the pointer. Nothing is written ;; until then: one drag is one undo step and one write to collaborators. (let [{c :clip st :store} (footage/entry id)] - (or (when-let [{:keys [path df kind ripple? other owner paths]} sliding] - (let [root (or owner open)] - (:clip (case kind - :out (nest/resize-out c root path df ripple?) - :in (nest/resize-in c root path df) - :roll (nest/roll c root other path df) - (if (seq paths) (nest/slide-many c root paths df) (nest/slide c root path df)))))) + (or (when sliding + (:clip (nest/drag c (or (:owner sliding) open) sliding))) (when-let [{:keys [sid id frame values edits]} gesture] ;; A held stage control owns the touched parameters completely. Make ;; them temporary static channels for the preview, so their existing diff --git a/frontend/src/arthur/ui/pool.cljs b/frontend/src/arthur/ui/pool.cljs index 65f32c5..6634186 100644 --- a/frontend/src/arthur/ui/pool.cljs +++ b/frontend/src/arthur/ui/pool.cljs @@ -204,7 +204,7 @@ `inside` is `{:count :open? :flip!}` for a row with rows under it; a row with none keeps the twisty's room, so names line up down a level. - `delete!` puts a cross beside the pencil, on hover as the pencil is." + `delete!` puts a cross beside the pencil while the row is picked." [{:keys [label sub sub2 title thumb on? open? main? disabled? rename depth inside delete!] :as opts}] (let [{:keys [key value begin! commit!]} rename @@ -255,25 +255,53 @@ ;; the browser test finds a row by the name a person reads. [:span.name label] (when (and main? sub2) [:span.detail sub2])] - (when begin! - [:span.pool-rename - {:title (str "rename " label " (F2)") - ;; Mouse-only by design — see the docstring. A `tabindex` here would - ;; make it interactive content inside a button, which is the thing - ;; being avoided, and F2 already reaches it from the keyboard. - :on-click (fn [^js e] (.stopPropagation e) (begin! key))} - "\u270E"]) - (when delete! - [:span.pool-rename.pool-delete - {:title (str "delete " label " (Delete)") - :on-click (fn [^js e] (.stopPropagation e) (delete!))} - "\u00D7"]) ;; The main row says both its facts under the name instead. - (when (and sub (not main?)) [:span.sub sub])]])])) + (when (and sub (not main?)) [:span.sub sub]) + ;; At the row's end, together, as a timeline row has them: the pencil + ;; on every row and the cross on what is picked. Two quick clicks on + ;; either are two clicks, not a double-click that opens the row. + [:span.pool-actions {:on-double-click (fn [^js e] (.stopPropagation e))} + (when begin! + [:span.pool-rename + {:title (str "rename " label " (F2)") + ;; Mouse-only by design — see the docstring. A `tabindex` here would + ;; make it interactive content inside a button, which is the thing + ;; being avoided, and F2 already reaches it from the keyboard. + :on-click (fn [^js e] (.stopPropagation e) (begin! key))} + "\u270E"]) + (when (and delete! on?) + [:span.pool-rename.pool-delete + {:title (str "delete " label " (Delete)") + :on-click (fn [^js e] (.stopPropagation e) (delete!))} + "\u00D7"])]]])])) ;; --------------------------------------------------------------------------- ;; the rows of each kind +(defonce ^:private anchor (atom nil)) + +(defn- pick! + "A click picks `what`, as a click on a timeline row does: with ⌘ it is added + to the picked or taken out of them, and with shift every row shown from the + last one clicked to this one is picked." + [^js e what] + (let [shown (vec (keep #(aget % "arthurPick") + (array-seq (.querySelectorAll (.closest (.-currentTarget e) ".pane.pool") + ".pool-item")))) + a (.indexOf shown @anchor) + b (.indexOf shown what)] + (cond + (or (.-metaKey e) (.-ctrlKey e)) (rf/dispatch [::ui/toggle-selection what]) + (and (.-shiftKey e) (<= 0 a) (<= 0 b)) + (rf/dispatch [::ui/select-many (subvec shown (min a b) (inc (max a b)))]) + :else (rf/dispatch [::ui/select what])) + (when-not (.-shiftKey e) (reset! anchor what)))) + +(defn- pickable + "The ref that tells `pick!` which rows are shown, in order." + [what] + (fn [^js el] (when el (aset el "arthurPick" what)))) + (defn- symbol-row [document sid {:keys [clip-id store palette selection open main rename depth inside]}] (let [sym (clip/symbol document sid) @@ -292,19 +320,20 @@ [tracing-thumb (:media sym)] [picture (symbol-thumb document sid store palette)]) :sub2 (str (:frames sym) "f · " nodes (if (= 1 nodes) " node" " nodes")) - :on? (= selection [:symbol sid]) + :on? (contains? selection [:symbol sid]) :open? (= sid open) :main? (= sid main) :depth depth :inside inside - :delete! (when-not (= sid main) #(rf/dispatch [::ui/delete-symbol sid])) + :delete! (when-not (= sid main) #(rf/dispatch [::ui/delete-symbols [sid]])) :rename (assoc rename :key [:symbol sid] :value label :commit! (fn [value] ((:begin! rename) nil) (rf/dispatch [::project/rename-symbol sid value]))) - :on-click #(rf/dispatch [::ui/select [:symbol sid]]) + :on-click #(pick! % [:symbol sid]) + :ref (pickable [:symbol sid]) :on-double-click #(rf/dispatch [::pb/open-symbol sid])} (carrying (str "symbol:" (subs (str sid) 1)) #(drag/symbol! clip-id sid open)))])) @@ -316,14 +345,15 @@ [row {:label (clip/symbol-name document sid) :sub (str "uses " (or (:name p) (:palette-ref sym))) :title "Palette transition definition" - :on? (= selection [:symbol sid]) + :on? (contains? selection [:symbol sid]) :rename (assoc rename :key [:symbol sid] :value (clip/symbol-name document sid) :commit! (fn [value] ((:begin! rename) nil) (rf/dispatch [::project/rename-symbol sid value]))) - :on-click #(rf/dispatch [::ui/select [:symbol sid]])}])) + :on-click #(pick! % [:symbol sid]) + :ref (pickable [:symbol sid])}])) (defn- footage-row [{:keys [id label frames fps video width height] :as f} chosen rename] ^{:key id} @@ -632,7 +662,7 @@ clip-id @(rf/subscribe [::render/clip-id]) store @(rf/subscribe [::render/store]) palette @(rf/subscribe [::render/palette]) - selection @(rf/subscribe [::sub/selection]) + selection (set @(rf/subscribe [::sub/selections])) open @(rf/subscribe [::render/open]) media @(rf/subscribe [::sub/project-footage]) {:keys [symbols palettes]} @(rf/subscribe [::project/assets]) diff --git a/frontend/src/arthur/ui/timeline.cljs b/frontend/src/arthur/ui/timeline.cljs index 73dd02b..cfa473b 100644 --- a/frontend/src/arthur/ui/timeline.cljs +++ b/frontend/src/arthur/ui/timeline.cljs @@ -790,8 +790,10 @@ ;; The palette row is the symbol's one palette lane: "palette" says all ;; there is to say, and it has no name of its own to change. named-lane? (and lane? (not= :palette kind)) + ;; A node row renames what it shows: an instance, its symbol. + renamable? (or named-lane? (and node? (some? (nth select 2 nil)))) selected? (contains? selections select) - editing? (and lane? (= select @renaming)) + editing? (and renamable? (= select @renaming)) begin-rename! (fn [] (reset! draft label) (reset! renaming select)) commit-rename! (fn [] (when (= select @renaming) @@ -827,7 +829,7 @@ ;; grouped with it into a new one; onto an edge of either, to be ;; restacked in front of it or behind it, in whichever symbol it is ;; in. All of them keep the picture as it is, but for the stacking. - node? (merge {:draggable true + node? (merge {:draggable (not editing?) :on-drag-start (fn [^js e] (.stopPropagation e) (.setData (.-dataTransfer e) "text/plain" "row") @@ -868,6 +870,7 @@ ;; is then suppressed by the browser). :draggable false :on-pointer-down (fn [^js e] (.stopPropagation e)) + :on-double-click (fn [^js e] (.stopPropagation e)) :on-click (fn [^js e] (.stopPropagation e) (rf/dispatch [::ui/set-row-expanded path (not expanded?)]))} @@ -880,7 +883,7 @@ (when lane? [:span.tl-ico {:aria-hidden true} [icon/view :lane]]) (if editing? [:input.tl-name-input - {:value @draft :auto-focus true :aria-label "lane name" + {:value @draft :auto-focus true :aria-label "name" :on-click #(.stopPropagation %) :on-double-click #(.stopPropagation %) :on-change #(reset! draft (.. % -target -value)) @@ -899,40 +902,43 @@ (cond named-lane? [:span.kind "·lane"] node? [:span.kind (if via (str "· in " via) (str "·" (name node-kind)))]) - (when named-lane? - [:button.tl-rename - {:title "rename lane" - :on-click (fn [^js e] (.stopPropagation e) (begin-rename!))} - "✎"]) - ;; A tracing layer's row switches it on and off, next to solo because the - ;; two are the same kind of thing: what this row shows, here, now, and - ;; nothing the picture keeps. A face's row switches its footage — its - ;; plate — which is the same switch wherever the face is placed. - (when-let [layer (cond (contains? (:traces tracing) of) [(second select) (nth select 2)] - (contains? (:plated tracing) of) [of :plate])] - (let [{:keys [on? hidden]} (:state tracing) - shown? (and on? (not (contains? hidden layer)))] - [:button {:class (str "tl-trace" (when shown? " on")) - :title (if (contains? (:traces tracing) of) - "show this tracing layer · never exported" - "show the footage this face was traced from") - :on-click (fn [^js e] - (.stopPropagation e) - (rf/dispatch [::ui/show-trace layer (not shown?)]))} - "T"])) - (when (= :instance node-kind) - [:button {:class (str "tl-solo" (when (contains? solo path) " on")) - :title "show only this on the stage (⇧ for more than one)" - :on-click (fn [^js e] - (.stopPropagation e) - (rf/dispatch [::ui/solo path (.-shiftKey e)]))} - "S"]) - (when (and node? (= select selection)) - [:button.tl-delete {:title "delete, with everything in it (⌫)" - :on-click (fn [^js e] - (.stopPropagation e) - (rf/dispatch [::ui/delete-selected]))} - "×"])])) + ;; The row's buttons sit together at its right end. Two quick clicks on + ;; one of them are two clicks, not a double-click that opens the row. + [:span.tl-actions {:on-double-click (fn [^js e] (.stopPropagation e))} + (when (and renamable? (not editing?)) + [:button.tl-rename + {:title (if (= :instance node-kind) "rename symbol · every placement follows" "rename") + :on-click (fn [^js e] (.stopPropagation e) (begin-rename!))} + "✎"]) + ;; A tracing layer's row switches it on and off, next to solo because the + ;; two are the same kind of thing: what this row shows, here, now, and + ;; nothing the picture keeps. A face's row switches its footage — its + ;; plate — which is the same switch wherever the face is placed. + (when-let [layer (cond (contains? (:traces tracing) of) [(second select) (nth select 2)] + (contains? (:plated tracing) of) [of :plate])] + (let [{:keys [on? hidden]} (:state tracing) + shown? (and on? (not (contains? hidden layer)))] + [:button {:class (str "tl-trace" (when shown? " on")) + :title (if (contains? (:traces tracing) of) + "show this tracing layer · never exported" + "show the footage this face was traced from") + :on-click (fn [^js e] + (.stopPropagation e) + (rf/dispatch [::ui/show-trace layer (not shown?)]))} + "T"])) + (when (= :instance node-kind) + [:button {:class (str "tl-solo" (when (contains? solo path) " on")) + :title "show only this on the stage (⇧ for more than one)" + :on-click (fn [^js e] + (.stopPropagation e) + (rf/dispatch [::ui/solo path (.-shiftKey e)]))} + "S"]) + (when (and node? (= select selection)) + [:button.tl-delete {:title "delete, with everything in it (⌫)" + :on-click (fn [^js e] + (.stopPropagation e) + (rf/dispatch [::ui/delete-selected]))} + "×"])]])) (defn- paint-key-selection! "Selection and preview are transient DOM state. Update them in one pass, @@ -1193,7 +1199,7 @@ ;; gesture; what it meant is known on release. (reset! sliding {:row path :path actual-path :kind gesture-kind :other other - :paths (when (and (= :slide gesture-kind) (not owner) + :paths (when (and (#{:slide :in :out} gesture-kind) (not owner) (contains? selected-set actual-select) (< 1 (count selections))) (mapv #(nth % 3) (filter #(= :node (first %)) selections))) @@ -1389,8 +1395,14 @@ [:span.tl-junction {:title "Drag the cut · the clip before it ends here and the one after it starts here" :on-pointer-down + ;; Between two clips of a selection, it is the end of the one + ;; before, and every selected end moves with it. (fn [^js e] - (begin! e (nth select 3) :roll select (nth (:select prev) 3) nil))}] + (if (and (< 1 (count selections)) + (contains? selected-set select) + (contains? selected-set (:select prev))) + (begin! e (nth (:select prev) 3) :out (:select prev) nil nil) + (begin! e (nth select 3) :roll select (nth (:select prev) 3) nil)))}] [:span.tl-edge.in {:title "Drag start" :on-pointer-down #(begin! % (nth select 3) :in select nil nil)}])) (when select diff --git a/frontend/test/arthur/domain/clipboard_test.cljs b/frontend/test/arthur/domain/clipboard_test.cljs index 8e8f94b..4491f4a 100644 --- a/frontend/test/arthur/domain/clipboard_test.cljs +++ b/frontend/test/arthur/domain/clipboard_test.cljs @@ -3,7 +3,8 @@ [arthur.domain.clip :as clip] [arthur.domain.clipboard :as clipboard] [arthur.domain.node :as node] - [arthur.domain.sequence-test :as fixture])) + [arthur.domain.sequence-test :as fixture] + [arthur.domain.symbol :as symbol])) (defn- ids [] (let [n (atom 0)] @@ -187,15 +188,18 @@ (is (:refused r)) (is (nil? (:clip r))))) -(deftest reparenting-into-a-lane-refuses-collision-atomically +(deftest reparenting-into-a-lane-claims-what-it-lands-on + ;; As one clip dropped into a lane does: the forest takes its frames from the + ;; clip already there. (let [doc (-> (reparent-document) (assoc-in [:symbols :box :display] :lane) (assoc-in [:symbols :box :nodes :occupied] (fixture/cel :occupied :drawing-a 4 4 0))) r (clipboard/move-many doc {} :main [(address :main :a [:a]) (address :main :b [:b])] [:target] 6 0)] - (is (:refused r)) - (is (nil? (:clip r))))) + (is (nil? (:refused r)) (str (:refused r))) + (is (nil? (get-in r [:clip :symbols :box :nodes :occupied])) "covered, it is gone") + (is (empty? (symbol/overlaps (get-in r [:clip :symbols :box])))))) (deftest dropping-the-forest-shifts-it-as-a-unit (let [r (clipboard/move-many (reparent-document) {} :main diff --git a/frontend/test/arthur/domain/sequence_test.cljs b/frontend/test/arthur/domain/sequence_test.cljs index bd90ddd..88187b2 100644 --- a/frontend/test/arthur/domain/sequence_test.cljs +++ b/frontend/test/arthur/domain/sequence_test.cljs @@ -858,12 +858,34 @@ (is (empty? (symbol/overlaps (get-in mixed [:symbols :main])))) (is (empty? (clip/problems mixed)))))) -(deftest moving-a-selection-in-a-lane-is-simultaneous - (let [doc (document) - moved (:clip (nest/slide-many doc :main [[:a] [:b]] 1))] - (is (nil? moved)) - (is (:refused (nest/slide-many doc :main [[:a] [:b]] 1)) - "the whole group refuses collision with the unselected insert"))) +(deftest moving-a-selection-in-a-lane-claims-what-it-lands-on + ;; One clip slid onto another takes its frames; a selection slid together does + ;; the same, and the clips in it keep their places among themselves. + (let [moved (:clip (nest/slide-many (document) :main [[:a] [:b]] 1)) + spans (into {} (map (juxt :id node/placed-span)) + (symbol/children (get-in moved [:symbols :main :nodes])))] + (is (= {:a [1 5] :b [5 9] :insert [9 12]} spans)) + (is (empty? (clip/problems moved))))) + +(defn- spans-after [result] + (is (nil? (:refused result)) (str (:refused result))) + (into {} (map (juxt :id node/placed-span)) + (symbol/children (get-in result [:clip :symbols :main :nodes])))) + +(deftest every-selected-clip-trims-by-the-same-drag + (let [all [[:a] [:b] [:insert]]] + (is (= {:a [0 6] :b [6 10] :insert [10 14]} + (spans-after (nest/resize-many (document) :main all :out 2 false))) + "each end moves two frames and eats the start of the clip after it") + (is (= {:a [0 6] :b [6 12] :insert [12 18]} + (spans-after (nest/resize-many (document) :main all :out 2 true))) + "rippled, every clip is two frames longer and nothing is eaten") + (is (= {:a [0 2] :b [4 6] :insert [8 10]} + (spans-after (nest/resize-many (document) :main all :out -2 false))) + "shortened, each leaves a gap") + (is (= {:a [0 9] :insert [9 17]} + (spans-after (nest/resize-many (document) :main all :out 5 false))) + "a clip eaten whole by an earlier one has no edge left to move"))) (deftest moving-all-lane-clips-preserves-their-spans (let [doc (document) diff --git a/frontend/test/browser/lane.mjs b/frontend/test/browser/lane.mjs index 29b2fab..b402fe4 100644 --- a/frontend/test/browser/lane.mjs +++ b/frontend/test/browser/lane.mjs @@ -110,7 +110,7 @@ try { assert.equal((await shot()).clip.symbols.main.display, undefined, 'a blank document starts as an ordinary symbol'); - await clickNew('symbol'); + await clickNew('+ symbol'); let s = await shot(); let placed = mainInstances(s); assert.equal(placed.length, 1, 'new symbol places one instance'); @@ -124,7 +124,7 @@ try { // create the lane inside that symbol. await evaluate(`re_frame.core.dispatch_sync(cljs.core.vector( cljs.core.keyword('arthur.events.ui/select'), null))`); - await clickNew('lane'); + await clickNew('+ lane'); s = await shot(); placed = mainInstances(s); assert.equal(placed.length, 2, 'explicit lane places a second symbol'); @@ -132,9 +132,9 @@ try { assert.equal(await evaluate('[...document.querySelectorAll(".tl-track:not(.palette)")].filter(t => t.arthurLane).length'), 1, 'the explicit lane is drawn as one linear track'); - assert.equal(await evaluate('document.querySelectorAll(".tl-label:not(.palette) .tl-rename").length'), 1, + assert.equal(await evaluate('document.querySelectorAll(".tl-label.lane:not(.palette) .tl-rename").length'), 1, 'the lane exposes its rename control'); - await evaluate('document.querySelector(".tl-label:not(.palette) .tl-rename").click()'); + await evaluate('document.querySelector(".tl-label.lane:not(.palette) .tl-rename").click()'); await sleep(80); assert(await evaluate(`(() => { const input = document.querySelector('.tl-name-input'); @@ -190,7 +190,7 @@ try { // that leaving a symbol selected creates the lane inside that symbol. await evaluate(`re_frame.core.dispatch_sync(cljs.core.vector( cljs.core.keyword('arthur.events.ui/select'), null))`); - await clickNew('lane'); + await clickNew('+ lane'); s = await shot(); assert.equal(laneSymbols(s).length, 2, 'a second explicit command creates a second lane'); const move = await evaluate(`(() => { @@ -220,7 +220,7 @@ try { await evaluate(`re_frame.core.dispatch_sync(cljs.core.vector( cljs.core.keyword('arthur.events.project/new'))) `); await sleep(250); - await clickNew('symbol'); + await clickNew('+ symbol'); const clipboardBaseline = (await shot()).clip; await shortcut('d', 'KeyD'); assert.equal(mainInstances(await shot()).length, 2, 'duplicate copies the selected instance'); diff --git a/static/arthur/app.css b/static/arthur/app.css index 4108148..d9db103 100644 --- a/static/arthur/app.css +++ b/static/arthur/app.css @@ -651,9 +651,8 @@ button.followable svg { width: 12px; height: 12px; display: block; } cursor: grab; } -/* Shrinks to the name, so the pencil sits against the end of the word rather - than out at the edge of the pane — and ellipses rather than pushing the - number off the row. */ +/* Shrinks to the name, and ellipses rather than pushing the number off the + row. */ .pool-item .text { display: flex; flex-direction: column; flex: 0 1 auto; min-width: 0; } .pool-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } @@ -721,13 +720,12 @@ button.followable svg { width: 12px; height: 12px; display: block; } white-space: nowrap; } -/* The pencil. A span and not a button — see `ui/pool`'s `row` — so it needs its - own centring and cursor rather than inheriting a control's. - - Hidden until the row is under the pointer or holds focus, because a column of - twenty pencils is a column of twenty pencils; `visibility` rather than - `display`, so it keeps its width and the name beside it does not reflow as the - pointer crosses the list. */ +/* The pencil and the cross, at the row's end as a timeline row has them. Two + slots wide whether or not the cross is there, so the numbers beside them stay + in one column. Spans and not buttons — see `ui/pool`'s `row` — so they need + their own centring and cursor rather than inheriting a control's. */ +.pool-actions { display: flex; flex: 0 0 30px; justify-content: flex-start; } +.pool-item > .text + .pool-actions { margin-left: auto; } .pool-rename { display: flex; align-items: center; @@ -739,11 +737,8 @@ button.followable svg { width: 12px; height: 12px; display: block; } color: var(--dim); line-height: 1; cursor: pointer; - visibility: hidden; } -.pool-row:hover .pool-rename, -.pool-row:focus-within .pool-rename { visibility: visible; } .pool-rename:hover { background: var(--hair); color: var(--fg); } /* Renaming. The input REPLACES the row at the same height, so a list does not @@ -1182,7 +1177,8 @@ button.followable svg { width: 12px; height: 12px; display: block; } .tl-label.lane:hover:not(.on) { background: #f8f6f0; } .tl-track.lane { background: rgba(0, 0, 0, 0.035); } .tl-name-input { min-width: 0; flex: 1; font: inherit; } -.tl-rename { margin-left: auto; padding: 0 3px; border: 0; background: none; color: var(--dim); } +.tl-actions { display: flex; align-items: center; margin-left: auto; } +.tl-rename { padding: 0 3px; border: 0; background: none; color: var(--dim); } .tl-rename:hover { color: var(--fg); } /* A fixed-width cell whether or not there is a triangle in it, so names at the @@ -1200,12 +1196,11 @@ button.followable svg { width: 12px; height: 12px; display: block; } .tl-twist:hover:not(:disabled) { background: none; color: var(--fg); } .tl-twist:disabled { opacity: 0; cursor: default; } -.tl-delete { margin-left: auto; padding: 0 4px; border: 0; background: none; color: var(--dim); } +.tl-delete { padding: 0 4px; border: 0; background: none; color: var(--dim); } .tl-delete:hover { color: var(--fg); } -.tl-solo, .tl-trace { margin-left: auto; padding: 0 4px; border: 0; background: none; color: var(--dim); font-size: 10px; } +.tl-solo, .tl-trace { padding: 0 4px; border: 0; background: none; color: var(--dim); font-size: 10px; } .tl-solo:hover, .tl-trace:hover { color: var(--fg); } .tl-solo.on, .tl-trace.on { color: var(--sel); font-weight: 600; } -.tl-solo + .tl-delete, .tl-trace + .tl-solo { margin-left: 0; } /* The ruler and the corner above the labels stay at the top of the body while the rows scroll under them: the ruler is the scrubber, and scrolling down to