From dcc81c92754f7861e559c1225234c840bf92142d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 31 Jan 2020 10:52:34 +0100 Subject: [PATCH] :paperclip: Add commented code related to undo/redo. --- common/uxbox/common/pages.cljc | 14 +++ frontend/src/uxbox/main/data/workspace.cljs | 86 +++++++++++++++++++ frontend/src/uxbox/main/geom.cljs | 8 +- .../uxbox/main/ui/workspace/shortcuts.cljs | 4 +- 4 files changed, 108 insertions(+), 4 deletions(-) diff --git a/common/uxbox/common/pages.cljc b/common/uxbox/common/pages.cljc index 47f8992acb..efd245882c 100644 --- a/common/uxbox/common/pages.cljc +++ b/common/uxbox/common/pages.cljc @@ -198,6 +198,20 @@ % operations)) data)) +;; (defn- process-mod-shape +;; [data {:keys [id operations] :as change}] +;; (if-let [shape (get-in data [:shapes-by-id id])] +;; (let [shape (reduce (fn [shape [_ att val]] +;; (if (nil? val) +;; (dissoc shape att) +;; (assoc shape att val))) +;; shape +;; operations)] +;; (if (empty? shape) +;; (update data :shapes-by-id dissoc id) +;; (update data :shapes-by-id assoc id shape))) +;; data)) + (defn- process-mod-opts [data {:keys [operations]}] (update data :options diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 1e55d79990..4e8986bdbd 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -168,6 +168,92 @@ (when (= page-id page-id') (rx/of (shapes-changes-commited msg))))))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Undo/Redo +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; (def undo-hierarchy +;; (-> (make-hierarchy) +;; (derive ::update-shape ::undo-signal) +;; (derive ::update-options ::undo-signal) +;; (derive ::move-selected-layer ::undo-signal) +;; (derive ::materialize-temporal-modifier-in-bulk ::undo-signal) +;; (derive ::update-dimensions ::undo-signal) +;; (derive ::add-shape ::undo-signal) +;; (derive ::add-canvas ::undo-signal))) + +;; (def MAX-UNDO-SIZE 50) + +;; (defn- conj-undo-entry +;; [undo data] +;; (let [undo (conj undo data)] +;; (if (> (count undo) MAX-UNDO-SIZE) +;; (into [] (take MAX-UNDO-SIZE undo)) +;; undo))) + +;; ptk/UpdateEvent +;; (update [_ state] +;; (let [pid (get-in state [:workspace-page :id]) +;; data (:workspace-data state) +;; undo (-> (get-in state [:undo pid] []) +;; (conj-undo-entry data))] +;; (prn "diff-and-commit-changes" "undo=" (count undo)) +;; (-> state +;; (assoc-in [:undo pid] undo) +;; (update :workspace-local dissoc :undo-index)))) + +;; (defn initialize-undo +;; [page-id] +;; (ptk/reify ::initialize-page +;; ptk/WatchEvent +;; (watch [_ state stream] +;; (let [stoper (rx/filter #(or (ptk/type? ::finalize %) +;; (ptk/type? ::initialize-page %)) +;; stream) +;; undo-event? #(or (isa? (ptk/type %) ::undo-signal) +;; (satisfies? IBatchedChange %))] +;; (->> stream +;; (rx/filter #(satisfies? IBatchedChange %)) +;; (rx/debounce 200) +;; (rx/map (constantly diff-and-commit-changes)) +;; (rx/take-until stoper)))))) + +;; (def undo +;; (ptk/reify ::undo +;; ptk/UpdateEvent +;; (update [_ state] +;; (let [pid (get-in state [:workspace-page :id]) +;; undo (get-in state [:undo pid] []) +;; index (get-in state [:workspace-local :undo-index]) +;; index (or index (dec (count undo)))] +;; (if (or (empty? undo) (= index 0)) +;; state +;; (let [index (dec index)] +;; (-> state +;; (assoc :workspace-data (nth undo index)) +;; (assoc-in [:workspace-local :undo-index] index)))))))) + +;; (def redo +;; (ptk/reify ::redo +;; ptk/UpdateEvent +;; (update [_ state] +;; (let [pid (get-in state [:workspace-page :id]) +;; undo (get-in state [:undo pid] []) +;; index (get-in state [:workspace-local :undo-index]) +;; index (or index (dec (count undo)))] +;; (if (or (empty? undo) (= index (dec (count undo)))) +;; state +;; (let [index (inc index)] +;; (-> state +;; (assoc :workspace-data (nth undo index)) +;; (assoc-in [:workspace-local :undo-index] index)))))))) + +;; (def reset-undo-index +;; (ptk/reify ::reset-undo-index +;; ptk/UpdateEvent +;; (update [_ state] +;; (update :workspace-local dissoc :undo-index)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; General workspace events ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/frontend/src/uxbox/main/geom.cljs b/frontend/src/uxbox/main/geom.cljs index 0ed4004983..b3a2a34fba 100644 --- a/frontend/src/uxbox/main/geom.cljs +++ b/frontend/src/uxbox/main/geom.cljs @@ -571,8 +571,12 @@ (gmt/matrix? modifier-mtx) (transform modifier-mtx))) -(def ^:private - xf-resolve-shapes +;; NOTE: we need applu `shape->rect-shape` 3 times because we need to +;; update the x1 x2 y1 y2 attributes on each step; this is because +;; some transform functions still uses that attributes. WE NEED TO +;; REFACTOR this, and remove any usage of the old xN yN attributes. + +(def ^:private xf-resolve-shapes (comp (map shape->rect-shape) (map resolve-modifier) (map shape->rect-shape) diff --git a/frontend/src/uxbox/main/ui/workspace/shortcuts.cljs b/frontend/src/uxbox/main/ui/workspace/shortcuts.cljs index 931b8bf7ad..f2e4397150 100644 --- a/frontend/src/uxbox/main/ui/workspace/shortcuts.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shortcuts.cljs @@ -31,8 +31,8 @@ :ctrl+0 #(st/emit! (dw/reset-zoom)) ;; :ctrl+r #(st/emit! (dw/toggle-flag :ruler)) :ctrl+d #(st/emit! dw/duplicate-selected) - ;; :ctrl+z #(st/emit! du/undo) - ;; :ctrl+shift+z #(st/emit! du/redo) + ;; :ctrl+z #(st/emit! dw/undo) + ;; :ctrl+shift+z #(st/emit! dw/redo) ;; :ctrl+y #(st/emit! du/redo) :ctrl+b #(st/emit! (dw/select-for-drawing :rect)) :ctrl+e #(st/emit! (dw/select-for-drawing :circle))