0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 18:18:24 -05:00

📎 Add commented code related to undo/redo.

This commit is contained in:
Andrey Antukh 2020-01-31 10:52:34 +01:00
parent 8d99bd723b
commit dcc81c9275
4 changed files with 108 additions and 4 deletions

View file

@ -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

View file

@ -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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -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)

View file

@ -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))