diff --git a/CHANGES.md b/CHANGES.md index 2b3b7d4a3..c1b254aa2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/common/src/app/common/text.cljc b/common/src/app/common/text.cljc index 396f7ab46..da941a60e 100644 --- a/common/src/app/common/text.cljc +++ b/common/src/app/common/text.cljc @@ -76,6 +76,10 @@ [node] (= "root" (:type node))) +(defn generate-shape-name + [text] + (subs text 0 (min 280 (count text)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DraftJS <-> Penpot Conversion ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index de56101f5..91ba1094e 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1726,7 +1726,7 @@ shape {:id id :type :text - :name "Text" + :name (txt/generate-shape-name text) :x x :y y :width width diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 4475f95a0..6af8929ac 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -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)))))) diff --git a/frontend/src/app/util/text_editor.cljs b/frontend/src/app/util/text_editor.cljs index dbe8d6112..157048186 100644 --- a/frontend/src/app/util/text_editor.cljs +++ b/frontend/src/app/util/text_editor.cljs @@ -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))