Repository: penpot/penpot
File: frontend/src/uxbox/main/data/workspace.cljs (ClojureScript)

Code before:
      (watch [_ state stream]
        (let [selected (get-in state [:workspace-local :selected])
              cdata    (prepare-selected state selected)]
          (->> (rx/from (wapi/write-to-clipboard cdata))
               (rx/catch on-copy-error)
               (rx/ignore)))))))


(declare select-pasted-objs)

(defn- paste-impl
  [{:keys [selected objects] :as data}]
  (letfn [(prepare-changes [state delta]
            "Prepare objects to paste: generate new id, give them unique names, move
            to the position of mouse pointer, and find in what frame they fit."
            (let [page-id (::page-id state)]
              (loop [existing-objs (get-in state [:workspace-data page-id :objects])
                     chgs []
                     id   (first selected)
                     ids  (rest selected)]
                (if (nil? id)
                  chgs
                  (let [result (prepare-change id existing-objs delta)
                        result (if (vector? result) result [result])]
                    (recur
                     (reduce conj existing-objs (map (fn [item] {(:id item) (:obj item)}) result))
                     (into chgs result)
                     (first ids)
                     (rest ids)))))))

          (prepare-change [id existing-objs delta]
            (let [obj (get objects id)]
              (if (= :frame (:type obj))
                (prepare-frame-change existing-objs obj delta)
                (prepare-shape-change existing-objs obj delta nil))))

          (prepare-shape-change [objects obj delta frame-id]
            (let [id (uuid/next)
                  name (impl-generate-unique-name objects (:name obj))
                  renamed-obj (assoc obj :id id :name name)
                  moved-obj (geom/move renamed-obj delta)
                  frame-id (if frame-id
                             frame-id
                             (calculate-frame-overlap objects moved-obj))
                  reframed-obj (assoc moved-obj :frame-id frame-id)]
              {:type :add-obj
               :id id
               :frame-id frame-id
               :obj reframed-obj}))

          (prepare-frame-change [objects obj delta]

Review comment (suggestion):
para operaciones con mapa es mejor usar `assoc` si entiendo bien el codigo.
(no lo he probado pero creo que esto seria mas logico:
```clojure
(reduce #(assoc %1 (:id %2) (:obj %2)) existing-objs result)
```



Code after:
        (let [selected (get-in state [:workspace-local :selected])
              cdata    (prepare-selected state selected)]
          (->> (rx/from (wapi/write-to-clipboard cdata))
               (rx/catch on-copy-error)
               (rx/ignore)))))))


(declare select-pasted-objs)

(defn- paste-impl
  [{:keys [selected objects] :as data}]
  (letfn [(prepare-changes [state delta]
            "Prepare objects to paste: generate new id, give them unique names, move
            to the position of mouse pointer, and find in what frame they fit."
            (let [page-id (::page-id state)]
              (loop [existing-objs (get-in state [:workspace-data page-id :objects])
                     chgs []
                     id   (first selected)
                     ids  (rest selected)]
                (if (nil? id)
                  chgs
                  (let [result (prepare-change id existing-objs delta)
                        result (if (vector? result) result [result])]
                    (recur
                     (reduce #(assoc %1 (:id %2) (:obj %2)) existing-objs result)
                     (into chgs result)
                     (first ids)
                     (rest ids)))))))

          (prepare-change [id existing-objs delta]
            (let [obj (get objects id)]
              (if (= :frame (:type obj))
                (prepare-frame-change existing-objs obj delta)
                (prepare-shape-change existing-objs obj delta nil))))

          (prepare-shape-change [objects obj delta frame-id]
            (let [id (uuid/next)
                  name (impl-generate-unique-name objects (:name obj))
                  renamed-obj (assoc obj :id id :name name)
                  moved-obj (geom/move renamed-obj delta)
                  frame-id (if frame-id
                             frame-id
                             (calculate-frame-overlap objects moved-obj))
                  reframed-obj (assoc moved-obj :frame-id frame-id)]
              {:type :add-obj
               :id id
               :frame-id frame-id
               :obj reframed-obj}))

          (prepare-frame-change [objects obj delta]
            (let [frame-id (uuid/next)