0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 07:50:43 -05:00

🐛 Fix naming of duplicated objects in copy&paste and others

This commit is contained in:
Andrés Moya 2021-08-12 16:43:32 +02:00 committed by Andrey Antukh
parent 58f0ad999c
commit a377c602cc
5 changed files with 16 additions and 18 deletions

View file

@ -68,19 +68,17 @@
(defn generate-unique-name
"A unique name generator"
([used basename]
(generate-unique-name used basename false))
([used basename prefix-first?]
(s/assert ::set-of-string used)
(s/assert ::us/string basename)
(let [[prefix initial] (extract-numeric-suffix basename)]
(loop [counter initial]
(let [candidate (if (and (= 1 counter) prefix-first?)
(str prefix)
(str prefix "-" counter))]
(if (contains? used candidate)
(recur (inc counter))
candidate))))))
[used basename]
(s/assert ::set-of-string used)
(s/assert ::us/string basename)
(if-not (contains? used basename)
basename
(let [[prefix initial] (extract-numeric-suffix basename)]
(loop [counter initial]
(let [candidate (str prefix "-" counter)]
(if (contains? used candidate)
(recur (inc counter))
candidate))))))
;; --- Shape attrs (Layers Sidebar)

View file

@ -182,7 +182,7 @@
shapes (shapes-for-grouping objects selected)]
(when-not (empty? shapes)
(let [[group rchanges uchanges]
(prepare-create-group objects page-id shapes "Group" false)]
(prepare-create-group objects page-id shapes "Group-1" false)]
(rx/of (dch/commit-changes {:redo-changes rchanges
:undo-changes uchanges
:origin it})
@ -221,7 +221,7 @@
(if (and (= (count shapes) 1)
(= (:type (first shapes)) :group))
[(first shapes) [] []]
(prepare-create-group objects page-id shapes "Group" true))
(prepare-create-group objects page-id shapes "Group-1" true))
rchanges (d/concat rchanges
[{:type :mod-obj

View file

@ -129,7 +129,7 @@
(if (and (= (count shapes) 1)
(= (:type (first shapes)) :group))
[(first shapes) [] []]
(dwg/prepare-create-group objects page-id shapes "Component" true))
(dwg/prepare-create-group objects page-id shapes "Component-1" true))
[new-shape new-shapes updated-shapes]
(make-component-shape group objects file-id)

View file

@ -331,7 +331,7 @@
(let [{:keys [tag attrs]} element-data
attrs (usvg/format-styles attrs)
element-data (cond-> element-data (map? element-data) (assoc :attrs attrs))
name (dwc/generate-unique-name unames (or (:id attrs) (tag->name tag)) true)
name (dwc/generate-unique-name unames (or (:id attrs) (tag->name tag)))
att-refs (usvg/find-attr-references attrs)
references (usvg/find-def-references (:defs svg-data) att-refs)

View file

@ -80,7 +80,7 @@
:obj shape}]))))
(defn group-shapes
([state label ids] (group-shapes state label ids "Group"))
([state label ids] (group-shapes state label ids "Group-1"))
([state label ids prefix]
(let [page (current-page state)
shapes (dwg/shapes-for-grouping (:objects page) ids)]