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
|
||||
|
||||
### :sparkles: New features
|
||||
- Default naming of text layers [Taiga #2836](https://tree.taiga.io/project/penpot/us/2836)
|
||||
|
||||
### :bug: Bugs fixed
|
||||
|
||||
|
|
|
@ -76,6 +76,10 @@
|
|||
[node]
|
||||
(= "root" (:type node)))
|
||||
|
||||
(defn generate-shape-name
|
||||
[text]
|
||||
(subs text 0 (min 280 (count text))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; DraftJS <-> Penpot Conversion
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
@ -1726,7 +1726,7 @@
|
|||
|
||||
shape {:id id
|
||||
:type :text
|
||||
:name "Text"
|
||||
:name (txt/generate-shape-name text)
|
||||
:x x
|
||||
:y y
|
||||
:width width
|
||||
|
|
|
@ -122,10 +122,14 @@
|
|||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(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))]
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
shape (get objects id)
|
||||
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))))))
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue