0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 06:32:38 -05:00

Merge pull request #3120 from penpot/superalex-default-naming-of-text-layers

🎉 Default naming of text layers
This commit is contained in:
Pablo Alba 2023-04-11 17:50:53 +02:00 committed by GitHub
commit ccaac2a5c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 5 deletions

View file

@ -5,6 +5,7 @@
### :boom: Breaking changes & Deprecations
### :sparkles: New features
- Default naming of text layers [Taiga #2836](https://tree.taiga.io/project/penpot/us/2836)
### :bug: Bugs fixed

View file

@ -76,6 +76,10 @@
[node]
(= "root" (:type node)))
(defn generate-shape-name
[text]
(subs text 0 (min 280 (count text))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DraftJS <-> Penpot Conversion
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -1726,7 +1726,7 @@
shape {:id id
:type :text
:name "Text"
:name (txt/generate-shape-name text)
:x x
:y y
:width width

View file

@ -124,8 +124,12 @@
(when (dwc/initialized? state)
(let [objects (wsh/lookup-page-objects state)
shape (get objects id)
content (-> (get-in state [:workspace-editor-state id])
(ted/get-editor-current-content))]
editor-state (get-in state [:workspace-editor-state id])
content (-> editor-state
(ted/get-editor-current-content))
text (-> (ted/get-editor-current-plain-text editor-state)
(txt/generate-shape-name))
new-shape? (nil? (:content shape))]
(if (ted/content-has-text? content)
(let [content (d/merge (ted/export-content content)
(dissoc (:content shape) :children))
@ -141,6 +145,8 @@
(let [{:keys [width height]} modifiers]
(-> shape
(assoc :content content)
(cond-> new-shape?
(assoc :name text))
(cond-> (or (some? width) (some? height))
(gsh/transform-shape (ctm/change-size shape width height)))))))
(dwu/commit-undo-transaction (:id shape))))))

View file

@ -43,6 +43,10 @@
(js->clj :keywordize-keys true)
(txt/convert-from-draft)))
(defn get-editor-current-plain-text
[state]
(.getPlainText (.getCurrentContent ^js state)))
(defn get-editor-current-content
[state]
(.getCurrentContent ^js state))