mirror of
https://github.com/penpot/penpot.git
synced 2026-05-30 04:08:08 +00:00
🐛 Fix problem with undo rename tokens
This commit is contained in:
parent
9439d63682
commit
63886d097b
@ -603,7 +603,7 @@
|
||||
(merge (meta it))))))))))
|
||||
|
||||
(defn bulk-update-tokens
|
||||
[set-id token-ids type old-path new-path]
|
||||
[set-id token-ids type old-path new-path & {:keys [undo-group]}]
|
||||
(dm/assert! (uuid? set-id))
|
||||
(dm/assert! (every? uuid? token-ids))
|
||||
(ptk/reify ::bulk-update-tokens
|
||||
@ -624,7 +624,9 @@
|
||||
(-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data))
|
||||
|
||||
token-ids)]
|
||||
token-ids)
|
||||
|
||||
changes (cond-> changes (some? undo-group) (assoc :undo-group undo-group))]
|
||||
(toggle-token-path (str (name type) "." old-path))
|
||||
(toggle-token-path (str (name type) "." new-path))
|
||||
(rx/of (dch/commit-changes changes)
|
||||
|
||||
@ -94,7 +94,7 @@
|
||||
|
||||
(defn remap-tokens
|
||||
"Main function to remap all token references when a token name changes"
|
||||
[old-token-name new-token-name]
|
||||
[old-token-name new-token-name & {:keys [undo-group]}]
|
||||
(ptk/reify ::remap-tokens
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
@ -120,14 +120,19 @@
|
||||
(some #(when (= (:name (:token %)) old-token-name) %) tokens-with-sets))
|
||||
attributes (set (map :attribute refs))]
|
||||
(if token
|
||||
(-> (pcb/with-container changes container)
|
||||
(pcb/update-shapes shape-ids
|
||||
(fn [shape]
|
||||
(update shape :applied-tokens
|
||||
#(merge % (cft/attributes-map attributes (:token token)))))))
|
||||
;; Create a new independent changes so we can call `with-file-data` after `with-container`
|
||||
;; otherwise it causes probelms looking up for objects
|
||||
(let [container-changes
|
||||
(-> (pcb/empty-changes)
|
||||
(pcb/with-container container)
|
||||
(pcb/with-file-data file-data)
|
||||
(pcb/update-shapes shape-ids
|
||||
(fn [shape]
|
||||
(update shape :applied-tokens
|
||||
#(merge % (cft/attributes-map attributes (:token token)))))))]
|
||||
(pcb/concat-changes changes container-changes))
|
||||
changes)))
|
||||
(-> (pcb/empty-changes)
|
||||
(pcb/with-file-data file-data)
|
||||
(pcb/with-library-data file-data))
|
||||
refs-by-container)
|
||||
|
||||
@ -141,7 +146,10 @@
|
||||
(pcb/set-token changes (ctob/get-id set) (:id token)
|
||||
(assoc token :value new-value))))))
|
||||
shape-changes
|
||||
(:token-aliases scan-results))]
|
||||
(:token-aliases scan-results))
|
||||
|
||||
token-changes
|
||||
(cond-> token-changes (some? undo-group) (assoc :undo-group undo-group))]
|
||||
|
||||
(log/info :hint "token-remapping"
|
||||
:old-name old-token-name
|
||||
@ -152,13 +160,13 @@
|
||||
|
||||
(defn bulk-remap-tokens
|
||||
"Helper function to remap a batch of tokens, used for node renaming"
|
||||
[tokens-in-path new-tokens]
|
||||
[tokens-in-path new-tokens & {:keys [undo-group]}]
|
||||
(ptk/reify ::bulk-remap-tokens
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(rx/concat
|
||||
(map (fn [old-token new-token]
|
||||
(remap-tokens (:name old-token) (:name new-token)))
|
||||
(remap-tokens (:name old-token) (:name new-token) :undo-group undo-group))
|
||||
tokens-in-path
|
||||
new-tokens)))))
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
[app.common.path-names :as cpn]
|
||||
[app.common.types.shape.layout :as ctsl]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.main.data.helpers :as dh]
|
||||
[app.main.data.modal :as modal]
|
||||
@ -220,10 +221,11 @@
|
||||
new-tokens (map (fn [token]
|
||||
(let [new-token-path (ctob/rename-path node token new-node-name)]
|
||||
(assoc token :name new-token-path)))
|
||||
tokens-in-path)]
|
||||
tokens-in-path)
|
||||
undo-group (uuid/next)]
|
||||
(st/emit!
|
||||
(dwtl/bulk-update-tokens selected-token-set-id tokens-in-path-ids type old-path new-node-path)
|
||||
(remap/bulk-remap-tokens tokens-in-path new-tokens)
|
||||
(dwtl/bulk-update-tokens selected-token-set-id tokens-in-path-ids type old-path new-node-path :undo-group undo-group)
|
||||
(remap/bulk-remap-tokens tokens-in-path new-tokens :undo-group undo-group)
|
||||
(dwtp/propagate-workspace-tokens)
|
||||
(modal/hide)))))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user