mirror of
https://github.com/penpot/penpot.git
synced 2025-06-11 16:11:38 +02:00
✨ Fixed undo/redo for automatic text adjustments
This commit is contained in:
parent
a227a0fe21
commit
0545e7cb28
3 changed files with 47 additions and 27 deletions
|
@ -75,15 +75,11 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)]
|
||||||
uidx (get-in state [:workspace-undo :index] ::not-found)]
|
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(when (some :page-id changes)
|
(when (some :page-id changes)
|
||||||
(rx/of (update-indices page-id)))
|
(rx/of (update-indices page-id)))
|
||||||
|
|
||||||
(when (and save-undo? (not= uidx ::not-found))
|
|
||||||
(rx/of (reset-undo uidx)))
|
|
||||||
|
|
||||||
(when (and save-undo? (seq undo-changes))
|
(when (and save-undo? (seq undo-changes))
|
||||||
(let [entry {:undo-changes undo-changes
|
(let [entry {:undo-changes undo-changes
|
||||||
:redo-changes changes}]
|
:redo-changes changes}]
|
||||||
|
@ -273,9 +269,16 @@
|
||||||
|
|
||||||
(defn- add-undo-entry
|
(defn- add-undo-entry
|
||||||
[state entry]
|
[state entry]
|
||||||
(if entry
|
(if (and entry
|
||||||
(let [state (update-in state [:workspace-undo :items] (fnil conj-undo-entry []) entry)]
|
(not-empty (:undo-changes entry))
|
||||||
(assoc-in state [:workspace-undo :index] (dec (count (get-in state [:workspace-undo :items])))))
|
(not-empty (:redo-changes entry)))
|
||||||
|
(let [index (get-in state [:workspace-undo :index] -1)
|
||||||
|
items (get-in state [:workspace-undo :items] [])
|
||||||
|
items (->> items (take (inc index)) (into []))
|
||||||
|
items (conj-undo-entry items entry)]
|
||||||
|
(-> state
|
||||||
|
(update :workspace-undo assoc :items items
|
||||||
|
:index (inc index))))
|
||||||
state))
|
state))
|
||||||
|
|
||||||
(defn- accumulate-undo-entry
|
(defn- accumulate-undo-entry
|
||||||
|
@ -317,6 +320,16 @@
|
||||||
(add-undo-entry (get-in state [:workspace-undo :transaction]))
|
(add-undo-entry (get-in state [:workspace-undo :transaction]))
|
||||||
(update :workspace-undo dissoc :transaction)))))
|
(update :workspace-undo dissoc :transaction)))))
|
||||||
|
|
||||||
|
(def pop-undo-into-transaction
|
||||||
|
(ptk/reify ::last-undo-into-transaction
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(let [index (get-in state [:workspace-undo :index] -1)]
|
||||||
|
|
||||||
|
(cond-> state
|
||||||
|
(>= index 0) (accumulate-undo-entry (get-in state [:workspace-undo :items index]))
|
||||||
|
(>= index 0) (update-in [:workspace-undo :index] dec))))))
|
||||||
|
|
||||||
(def undo
|
(def undo
|
||||||
(ptk/reify ::undo
|
(ptk/reify ::undo
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
|
@ -399,17 +412,19 @@
|
||||||
(let [id (first ids)
|
(let [id (first ids)
|
||||||
obj1 (get objects id)
|
obj1 (get objects id)
|
||||||
obj2 (f obj1)
|
obj2 (f obj1)
|
||||||
|
rch-operations (generate-operations obj1 obj2)
|
||||||
|
uch-operations (generate-operations obj2 obj1)
|
||||||
rchg {:type :mod-obj
|
rchg {:type :mod-obj
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:operations (generate-operations obj1 obj2)
|
:operations rch-operations
|
||||||
:id id}
|
:id id}
|
||||||
uchg {:type :mod-obj
|
uchg {:type :mod-obj
|
||||||
:page-id page-id
|
:page-id page-id
|
||||||
:operations (generate-operations obj2 obj1)
|
:operations uch-operations
|
||||||
:id id}]
|
:id id}]
|
||||||
(recur (next ids)
|
(recur (next ids)
|
||||||
(conj rch rchg)
|
(if (empty? rch-operations) rch (conj rch rchg))
|
||||||
(conj uch uchg))))))))))
|
(if (empty? uch-operations) uch (conj uch uchg)))))))))))
|
||||||
|
|
||||||
|
|
||||||
(defn update-shapes-recursive
|
(defn update-shapes-recursive
|
||||||
|
|
|
@ -357,24 +357,29 @@
|
||||||
#(let [self-node (mf/ref-val self-ref)
|
#(let [self-node (mf/ref-val self-ref)
|
||||||
paragraph-node (when self-node (dom/query self-node ".paragraph-set"))]
|
paragraph-node (when self-node (dom/query self-node ".paragraph-set"))]
|
||||||
(when paragraph-node
|
(when paragraph-node
|
||||||
(let [{:keys [width height]} (dom/get-bounding-rect paragraph-node)]
|
(let [{:keys [width height]} (dom/get-bounding-rect paragraph-node)
|
||||||
(cond
|
undo-transaction (get-in @st/state [:workspaceundo :transaction])]
|
||||||
(and (:overflow-text shape) (not= :fixed (:grow-type shape)))
|
(when (not undo-transaction) (st/emit! dwc/start-undo-transaction))
|
||||||
(st/emit! (dwt/update-overflow-text id false))
|
(when (or (not= (:width shape) width)
|
||||||
|
(not= (:height shape) height))
|
||||||
|
(cond
|
||||||
|
(and (:overflow-text shape) (not= :fixed (:grow-type shape)))
|
||||||
|
(st/emit! (dwt/update-overflow-text id false))
|
||||||
|
|
||||||
(and (= :fixed (:grow-type shape)) (not (:overflow-text shape)) (> height (:height shape)))
|
(and (= :fixed (:grow-type shape)) (not (:overflow-text shape)) (> height (:height shape)))
|
||||||
(st/emit! (dwt/update-overflow-text id true))
|
(st/emit! (dwt/update-overflow-text id true))
|
||||||
|
|
||||||
(and (= :fixed (:grow-type shape)) (:overflow-text shape) (<= height (:height shape)))
|
(and (= :fixed (:grow-type shape)) (:overflow-text shape) (<= height (:height shape)))
|
||||||
(st/emit! (dwt/update-overflow-text id false))
|
(st/emit! (dwt/update-overflow-text id false))
|
||||||
|
|
||||||
(= grow-type :auto-width)
|
(= grow-type :auto-width)
|
||||||
(st/emit! (dw/update-dimensions [id] :width width)
|
(st/emit! (dw/update-dimensions [id] :width width)
|
||||||
(dw/update-dimensions [id] :height height))
|
(dw/update-dimensions [id] :height height))
|
||||||
|
|
||||||
(= grow-type :auto-height)
|
(= grow-type :auto-height)
|
||||||
(st/emit! (dw/update-dimensions [id] :height height))
|
(st/emit! (dw/update-dimensions [id] :height height))
|
||||||
)))))))
|
))
|
||||||
|
(when (not undo-transaction) (st/emit! dwc/discard-undo-transaction))))))))
|
||||||
|
|
||||||
[:foreignObject {:ref self-ref
|
[:foreignObject {:ref self-ref
|
||||||
:transform (geom/transform-matrix shape)
|
:transform (geom/transform-matrix shape)
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
(let [{:keys [redo-changes]} entry]
|
(let [{:keys [redo-changes]} entry]
|
||||||
[:li.undo-entry {:class (when is-transaction? "transaction")}
|
[:li.undo-entry {:class (when is-transaction? "transaction")}
|
||||||
(for [[idx-change {:keys [type id operations]}] (map-indexed vector redo-changes)]
|
(for [[idx-change {:keys [type id operations]}] (map-indexed vector redo-changes)]
|
||||||
[:div.undo-entry-change
|
[:div.undo-entry-change {:key (str "change-" idx-change)}
|
||||||
[:div.undo-entry-change-data (when type (str type)) " " (when id (str (get-in objects [id :name] (subs (str id) 0 8))))]
|
[:div.undo-entry-change-data (when type (str type)) " " (when id (str (get-in objects [id :name] (subs (str id) 0 8))))]
|
||||||
(when operations
|
(when operations
|
||||||
[:div.undo-entry-change-data (str/join ", " (map (comp name :attr) operations))])])]))
|
[:div.undo-entry-change-data (str/join ", " (map (comp name :attr) operations))])])]))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue