diff --git a/CHANGES.md b/CHANGES.md index 13bc3d076..ba3ac7d27 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -81,6 +81,7 @@ - Fix exports menu on viewer mode [Taiga #5568](https://tree.taiga.io/project/penpot/issue/5568) - Fix create empty comments [Taiga #5536](https://tree.taiga.io/project/penpot/issue/5536) - Fix position of text cursor is a bit too high in Invitations section [Taiga #5511](https://tree.taiga.io/project/penpot/issue/5511) +- Fix undo when updating several texts [Taiga #5197](https://tree.taiga.io/project/penpot/issue/5197) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index eea3ec6c8..2f002f7c9 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -627,6 +627,18 @@ (rx/of (update-text-attrs {:id id :attrs attrs})) (rx/empty))))))) +(defn update-all-attrs + [ids attrs] + (ptk/reify ::update-all-attrs + ptk/WatchEvent + (watch [_ _ _] + (let [undo-id (js/Symbol)] + (rx/concat + (rx/of (dwu/start-undo-transaction undo-id)) + (->> (rx/from ids) + (rx/map #(update-attrs % attrs))) + (rx/of (dwu/commit-undo-transaction undo-id))))))) + (defn apply-typography "A higher level event that has the resposability of to apply the diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs index e373bb79a..a7f85fe0f 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/text.cljs @@ -172,16 +172,16 @@ emit-update! (mf/use-callback (mf/deps values) - (fn [id attrs] - (st/emit! (dwt/save-font (-> (merge txt/default-text-attrs values attrs) - (select-keys dwt/text-attrs))) - (dwt/update-attrs id attrs)))) + (fn [ids attrs] + (st/emit! (dwt/save-font (-> (merge txt/default-text-attrs values attrs) + (select-keys dwt/text-attrs))) + (dwt/update-all-attrs ids attrs)))) on-change (mf/use-callback (mf/deps ids emit-update!) (fn [attrs] - (run! #(emit-update! % attrs) ids))) + (emit-update! ids attrs))) typography (mf/use-memo @@ -211,8 +211,9 @@ typography (dwt/generate-typography-name typography) id (uuid/next)] (st/emit! (dwl/add-typography (assoc typography :id id) false)) - (run! #(emit-update! % {:typography-ref-id id - :typography-ref-file file-id}) ids))) + (emit-update! ids + {:typography-ref-id id + :typography-ref-file file-id}))) handle-detach-typography (mf/use-callback