0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 16:18:11 -05:00

🐛 Fix duplicate with alt and undo only undo one step

This commit is contained in:
Pablo Alba 2023-02-13 17:39:33 +01:00 committed by Alejandro Alonso
parent 0f07def536
commit 813a188e24
6 changed files with 78 additions and 23 deletions

View file

@ -5,7 +5,11 @@
- Fix invite members button text [Taiga #4794](https://tree.taiga.io/project/penpot/issue/4794) - Fix invite members button text [Taiga #4794](https://tree.taiga.io/project/penpot/issue/4794)
- Fix problem with opacity in frames [Taiga #4795](https://tree.taiga.io/project/penpot/issue/4795) - Fix problem with opacity in frames [Taiga #4795](https://tree.taiga.io/project/penpot/issue/4795)
<<<<<<< HEAD
- Fix correct behaviour for space-around and added space-evenly option - Fix correct behaviour for space-around and added space-evenly option
=======
- Fix duplicate with alt and undo only undo one step [Taiga #4746](https://tree.taiga.io/project/penpot/issue/4746)
>>>>>>> d262fc2b7 (:bug: Fix duplicate with alt and undo only undo one step)
## 1.17.2 ## 1.17.2

View file

@ -34,6 +34,23 @@
(declare commit-changes) (declare commit-changes)
(defn- add-group-id
[changes state]
(let [undo (:workspace-undo state)
items (:items undo)
index (or (:index undo) (dec (count items)))
prev-item (when-not (or (empty? items) (= index -1))
(get items index))
group-id (:group-id prev-item)
add-group-id? (and
(not (nil? group-id))
(= (get-in changes [:redo-changes 0 :type]) :mod-obj)
(= (get-in prev-item [:redo-changes 0 :type]) :add-obj)) ;; This is a copy-and-move with mouse+alt
]
(cond-> changes add-group-id? (assoc :group-id group-id))))
(def commit-changes? (ptk/type? ::commit-changes)) (def commit-changes? (ptk/type? ::commit-changes))
(defn update-shapes (defn update-shapes
@ -64,7 +81,8 @@
(-> (pcb/empty-changes it page-id) (-> (pcb/empty-changes it page-id)
(pcb/set-save-undo? save-undo?) (pcb/set-save-undo? save-undo?)
(pcb/with-objects objects)) (pcb/with-objects objects))
ids)] ids)
changes (add-group-id changes state)]
(rx/concat (rx/concat
(if (seq (:redo-changes changes)) (if (seq (:redo-changes changes))
(let [changes (cond-> changes reg-objects? (pcb/resize-parents ids))] (let [changes (cond-> changes reg-objects? (pcb/resize-parents ids))]
@ -147,7 +165,7 @@
(defn commit-changes (defn commit-changes
[{:keys [redo-changes undo-changes [{:keys [redo-changes undo-changes
origin save-undo? file-id] origin save-undo? file-id group-id]
:or {save-undo? true}}] :or {save-undo? true}}]
(log/debug :msg "commit-changes" (log/debug :msg "commit-changes"
:js/redo-changes redo-changes :js/redo-changes redo-changes
@ -164,7 +182,8 @@
:changes redo-changes :changes redo-changes
:page-id page-id :page-id page-id
:frames frames :frames frames
:save-undo? save-undo?}) :save-undo? save-undo?
:group-id group-id})
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -212,5 +231,6 @@
(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 redo-changes}] :redo-changes redo-changes
:group-id group-id}]
(rx/of (dwu/append-undo entry))))))))))) (rx/of (dwu/append-undo entry)))))))))))

View file

@ -27,6 +27,7 @@
(defn interrupt? [e] (= e :interrupt)) (defn interrupt? [e] (= e :interrupt))
(declare undo-to-index)
(defn- assure-valid-current-page (defn- assure-valid-current-page
[] []
@ -60,13 +61,25 @@
items (:items undo) items (:items undo)
index (or (:index undo) (dec (count items)))] index (or (:index undo) (dec (count items)))]
(when-not (or (empty? items) (= index -1)) (when-not (or (empty? items) (= index -1))
(let [changes (get-in items [index :undo-changes])] (let [item (get items index)
changes (:undo-changes item)
group-id (:group-id item)
find-first-group-idx (fn ffgidx[index]
(let [item (get items index)]
(if (= (:group-id item) group-id)
(ffgidx (dec index))
(inc index))))
undo-group-index (when group-id
(find-first-group-idx index))]
(if group-id
(rx/of (undo-to-index (dec undo-group-index)))
(rx/of (dwu/materialize-undo changes (dec index)) (rx/of (dwu/materialize-undo changes (dec index))
(dch/commit-changes {:redo-changes changes (dch/commit-changes {:redo-changes changes
:undo-changes [] :undo-changes []
:save-undo? false :save-undo? false
:origin it}) :origin it})
(assure-valid-current-page)))))))))) (assure-valid-current-page)))))))))))
(def redo (def redo
(ptk/reify ::redo (ptk/reify ::redo
@ -79,12 +92,24 @@
items (:items undo) items (:items undo)
index (or (:index undo) (dec (count items)))] index (or (:index undo) (dec (count items)))]
(when-not (or (empty? items) (= index (dec (count items)))) (when-not (or (empty? items) (= index (dec (count items))))
(let [changes (get-in items [(inc index) :redo-changes])] (let [item (get items (inc index))
changes (:redo-changes item)
group-id (:group-id item)
find-last-group-idx (fn flgidx [index]
(let [item (get items index)]
(if (= (:group-id item) group-id)
(flgidx (inc index))
(dec index))))
redo-group-index (when group-id
(find-last-group-idx (inc index)))]
(if group-id
(rx/of (undo-to-index redo-group-index))
(rx/of (dwu/materialize-undo changes (inc index)) (rx/of (dwu/materialize-undo changes (inc index))
(dch/commit-changes {:redo-changes changes (dch/commit-changes {:redo-changes changes
:undo-changes [] :undo-changes []
:origin it :origin it
:save-undo? false})))))))))) :save-undo? false})))))))))))
(defn undo-to-index (defn undo-to-index
"Repeat undoing or redoing until dest-index is reached." "Repeat undoing or redoing until dest-index is reached."
@ -99,7 +124,7 @@
items (:items undo) items (:items undo)
index (or (:index undo) (dec (count items)))] index (or (:index undo) (dec (count items)))]
(when (and (some? items) (when (and (some? items)
(<= 0 dest-index (dec (count items)))) (<= -1 dest-index (dec (count items))))
(let [changes (vec (apply concat (let [changes (vec (apply concat
(cond (cond
(< dest-index index) (< dest-index index)

View file

@ -485,7 +485,10 @@
(gpt/subtract new-pos pt-obj))))) (gpt/subtract new-pos pt-obj)))))
(defn duplicate-selected [move-delta?] (defn duplicate-selected
([move-delta?]
(duplicate-selected move-delta? false))
([move-delta? add-group-id?]
(ptk/reify ::duplicate-selected (ptk/reify ::duplicate-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
@ -502,6 +505,8 @@
changes (->> (prepare-duplicate-changes objects page selected delta it) changes (->> (prepare-duplicate-changes objects page selected delta it)
(duplicate-changes-update-indices objects selected)) (duplicate-changes-update-indices objects selected))
changes (cond-> changes add-group-id? (assoc :group-id (uuid/random)))
id-original (first selected) id-original (first selected)
new-selected (->> changes new-selected (->> changes
@ -525,7 +530,7 @@
(select-shapes new-selected) (select-shapes new-selected)
(ptk/data-event :layout/update frames) (ptk/data-event :layout/update frames)
(memorize-duplicated id-original id-duplicated) (memorize-duplicated id-original id-duplicated)
(dwu/commit-undo-transaction undo-id))))))))) (dwu/commit-undo-transaction undo-id))))))))))
(defn change-hover-state (defn change-hover-state
[id value] [id value]

View file

@ -382,7 +382,7 @@
(if alt? (if alt?
;; When alt is down we start a duplicate+move ;; When alt is down we start a duplicate+move
(rx/of (start-move-duplicate initial) (rx/of (start-move-duplicate initial)
(dws/duplicate-selected false)) (dws/duplicate-selected false true))
;; Otherwise just plain old move ;; Otherwise just plain old move
(rx/of (start-move initial selected)))))) (rx/of (start-move initial selected))))))

View file

@ -55,10 +55,11 @@
state)) state))
(defn- accumulate-undo-entry (defn- accumulate-undo-entry
[state {:keys [undo-changes redo-changes]}] [state {:keys [undo-changes redo-changes group-id]}]
(-> state (-> state
(update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %)) (update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %))
(update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes)))) (update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes))
(assoc-in [:workspace-undo :transaction :group-id] group-id)))
(defn append-undo (defn append-undo
[entry] [entry]