   ptk/UpdateEvent
   (update [_ state]
     (let [page-id (get-in state [:workspace :page])
-          undo (get-in state [:undo page-id])
-          stack (:stack undo)
-          selected (:selected undo)]
+          undo-state (get-in state [:undo page-id])
+          stack (:stack undo-state)
+          selected (:selected undo-state)]
       (if (or (nil? selected) (zero? selected))
         state
         (let [pointer (dec selected)
-              data (nth stack pointer)
+              undo (nth stack pointer)
+              data (:data undo)
+              metadata (:metadata undo)
               page (get-in state [:pages page-id])
-              packed (assoc page :data data)]
+              packed (assoc page :data data :metadata metadata)]
 
           ;; (println "Redo: pointer=" pointer)
           ;; (println "Redo: packed=")

(defrecord SaveUndoEntry [id]
  ptk/UpdateEvent
  (update [_ state]
    (let [page (udp/pack-page state id)]
      (-> state
          (update-in [:undo id :stack] #(cons (:data page) %))
          (assoc-in [:undo id :selected] 0)))))

  ;; ptk/EffectEvent
  ;; (effect [_ state]
  ;;   (let [undo (get-in state [:undo id])]
  ;;     (println (pr-str undo)))))

(defn save-undo-entry
  [id]

  ptk/UpdateEvent
  (update [_ state]
    (let [page-id (get-in state [:workspace :page])
          undo-state (get-in state [:undo page-id])
          stack (:stack undo-state)
          selected (:selected undo-state 0)]
      (if (>= selected (dec (count stack)))
        state
        (let [pointer (inc selected)
              page (get-in state [:pages page-id])
              undo (nth stack pointer)
              data (:data undo)
              metadata (:metadata undo)
              packed (assoc page :data data :metadata metadata)]

          ;; (println "Undo: pointer=" pointer)
          ;; (println "Undo: packed=")
