mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 16:00:19 -05:00
🎉 Default naming of text layers
This commit is contained in:
parent
08c6ebe10c
commit
5993b9855e
5 changed files with 20 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
||||||
### :boom: Breaking changes & Deprecations
|
### :boom: Breaking changes & Deprecations
|
||||||
|
|
||||||
### :sparkles: New features
|
### :sparkles: New features
|
||||||
|
- Default naming of text layers [Taiga #2836](https://tree.taiga.io/project/penpot/us/2836)
|
||||||
|
|
||||||
### :bug: Bugs fixed
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,10 @@
|
||||||
[node]
|
[node]
|
||||||
(= "root" (:type node)))
|
(= "root" (:type node)))
|
||||||
|
|
||||||
|
(defn generate-shape-name
|
||||||
|
[text]
|
||||||
|
(subs text 0 (min 280 (count text))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; DraftJS <-> Penpot Conversion
|
;; DraftJS <-> Penpot Conversion
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
@ -1726,7 +1726,7 @@
|
||||||
|
|
||||||
shape {:id id
|
shape {:id id
|
||||||
:type :text
|
:type :text
|
||||||
:name "Text"
|
:name (txt/generate-shape-name text)
|
||||||
:x x
|
:x x
|
||||||
:y y
|
:y y
|
||||||
:width width
|
:width width
|
||||||
|
|
|
@ -122,10 +122,14 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(when (dwc/initialized? state)
|
(when (dwc/initialized? state)
|
||||||
(let [objects (wsh/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
shape (get objects id)
|
shape (get objects id)
|
||||||
content (-> (get-in state [:workspace-editor-state id])
|
editor-state (get-in state [:workspace-editor-state id])
|
||||||
(ted/get-editor-current-content))]
|
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)
|
(if (ted/content-has-text? content)
|
||||||
(let [content (d/merge (ted/export-content content)
|
(let [content (d/merge (ted/export-content content)
|
||||||
(dissoc (:content shape) :children))
|
(dissoc (:content shape) :children))
|
||||||
|
@ -141,6 +145,8 @@
|
||||||
(let [{:keys [width height]} modifiers]
|
(let [{:keys [width height]} modifiers]
|
||||||
(-> shape
|
(-> shape
|
||||||
(assoc :content content)
|
(assoc :content content)
|
||||||
|
(cond-> new-shape?
|
||||||
|
(assoc :name text))
|
||||||
(cond-> (or (some? width) (some? height))
|
(cond-> (or (some? width) (some? height))
|
||||||
(gsh/transform-shape (ctm/change-size shape width height)))))))
|
(gsh/transform-shape (ctm/change-size shape width height)))))))
|
||||||
(dwu/commit-undo-transaction (:id shape))))))
|
(dwu/commit-undo-transaction (:id shape))))))
|
||||||
|
|
|
@ -43,6 +43,10 @@
|
||||||
(js->clj :keywordize-keys true)
|
(js->clj :keywordize-keys true)
|
||||||
(txt/convert-from-draft)))
|
(txt/convert-from-draft)))
|
||||||
|
|
||||||
|
(defn get-editor-current-plain-text
|
||||||
|
[state]
|
||||||
|
(.getPlainText (.getCurrentContent ^js state)))
|
||||||
|
|
||||||
(defn get-editor-current-content
|
(defn get-editor-current-content
|
||||||
[state]
|
[state]
|
||||||
(.getCurrentContent ^js state))
|
(.getCurrentContent ^js state))
|
||||||
|
|
Loading…
Reference in a new issue