diff --git a/frontend/src/arthur/events/ui.cljs b/frontend/src/arthur/events/ui.cljs index 50575c7..ce7e5be 100644 --- a/frontend/src/arthur/events/ui.cljs +++ b/frontend/src/arthur/events/ui.cljs @@ -21,6 +21,7 @@ (:require [arthur.domain.clip :as clip] [arthur.domain.correction :as correction] [arthur.domain.gesture :as gesture] + [arthur.domain.history :as history] [arthur.domain.nest :as nest] [arthur.domain.node :as node] [arthur.domain.lane :as lane] @@ -758,20 +759,30 @@ ::gesture ;; A transform in the middle of a drag on the stage, `{:sid :id :frame ;; :values}`, drawn by `::render/clip` as `::sliding` is; nil when abandoned. + ;; Auto-key is different: its first movement must materialize the key, or the + ;; channel's existing interpolation remains the document truth throughout the + ;; drag and fights the hand moving it. Each move therefore updates the real key + ;; while history/hold makes the entire gesture one undo step. (fn [db [_ g]] - (if g - (assoc-in db [:ui :gesture] - (assoc g :auto-key? (boolean (get-in db [:ui :auto-key?])))) - (update db :ui dissoc :gesture)))) + (let [active (get-in db [:ui :gesture]) + auto? (if active (:auto-key? active) (boolean (get-in db [:ui :auto-key?])))] + (if g + (let [{:keys [sid id frame values] :as g} (assoc g :auto-key? auto?)] + (cond-> db + (and auto? (nil? active)) (edit/history history/hold) + auto? (edit/edit #(gesture/apply-values % sid id frame values true)) + true (assoc-in [:ui :gesture] g))) + (cond-> (update db :ui dissoc :gesture) + (:auto-key? active) (edit/history history/settle)))))) (rf/reg-event-db ::transform ;; The drag let go: one edit, so one undo step and one write to collaborators. (fn [db [_ {:keys [sid id frame values]}]] - (cond-> (update db :ui dissoc :gesture) - (seq values) (edit/edit #(gesture/apply-values - % sid id frame values - (boolean (get-in db [:ui :auto-key?]))))))) + (let [auto? (boolean (get-in db [:ui :gesture :auto-key?]))] + (cond-> (update db :ui dissoc :gesture) + (seq values) (edit/edit #(gesture/apply-values % sid id frame values auto?)) + auto? (edit/history history/settle))))) (rf/reg-event-db ::delete-selected