diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index 4e4a429e5..c42c3a0a2 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -595,8 +595,6 @@ ;; function. Better check it and test toroughly when activating ;; components-v2 mode. in-copy? (ctk/in-component-copy? shape) - root-name? (and (= group :name-group) - (:component-root? shape)) ;; For geometric attributes, there are cases in that the value changes ;; slightly (e.g. when rounding to pixel, or when recalculating text @@ -607,7 +605,6 @@ (gsh/close-attrs? attr val shape-val))] (when (and group (not ignore) (not equal?) - (not root-name?) (not (and ignore-geometry is-geometry?))) ;; Notify touched even if it's not copy, because it may be a main instance (on-touched shape)) @@ -618,7 +615,6 @@ ;; In some cases we need to ignore touched only if the attribute is ;; geometric (position, width or transformation). (and in-copy? group (not ignore) (not equal?) - (not root-name?) (not (and ignore-geometry is-geometry?))) (-> (update :touched cph/set-touched-group group) (dissoc :remote-synced?)) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index f71ff3415..ebbb49a73 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -366,6 +366,11 @@ (rx/of (dch/commit-changes changes))))))) +(defn rename-component-and-main-instance + [component-id shape-id name page-id] + (st/emit! (rename-component component-id name) + (dch/update-shapes [shape-id] #(merge % {:name name}) {:page-id page-id :stack-undo? true}))) + (defn duplicate-component "Create a new component copied from the one with the given id." [library-id component-id] diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index f707d41db..b35e30358 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -1196,14 +1196,10 @@ :val (get dest-shape attr) :ignore-touched true} - attr-group (get cp/component-sync-attrs attr) - - root-name? (and (= attr-group :name-group) - (:component-root? dest-shape))] + attr-group (get cp/component-sync-attrs attr)] (if (or (= (get origin-shape attr) (get dest-shape attr)) - (and (touched attr-group) omit-touched?) - root-name?) + (and (touched attr-group) omit-touched?)) (recur (next attrs) roperations uoperations) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index 06cba9330..7502d59be 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -639,8 +639,13 @@ (mf/use-fn (mf/deps @state) (fn [new-name] - (st/emit! (dwl/rename-component (:renaming @state) new-name)) - (swap! state assoc :renaming nil))) + (let [component-id (:renaming @state) + component (dm/get-in file [:components component-id]) + main-instance-id (:main-instance-id component) + main-instance-page (:main-instance-page component)] + + (dwl/rename-component-and-main-instance component-id main-instance-id new-name main-instance-page) + (swap! state assoc :renaming nil)))) cancel-rename (mf/use-fn @@ -1778,7 +1783,7 @@ (st/emit! (dwl/add-typography typography) (ptk/event ::ev/event {::ev/name "add-asset-to-library" :asset-type "typography"})))) - + handle-change (mf/use-fn (mf/deps file-id) diff --git a/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs b/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs index ce118aa43..26b03c5b8 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs @@ -8,6 +8,7 @@ (:require-macros [app.main.style :refer [css]]) (:require [app.main.data.workspace :as dw] + [app.main.data.workspace.libraries :as dwl] [app.main.store :as st] [app.main.ui.context :as ctx] [app.util.dom :as dom] @@ -30,13 +31,16 @@ (swap! local assoc :edition true))) accept-edit (fn [] - (let [name-input (mf/ref-val name-ref) - name (dom/get-value name-input)] + (let [name-input (mf/ref-val name-ref) + name (str/trim (dom/get-value name-input)) + main-instance? (:main-instance? shape)] (on-stop-edit) (swap! local assoc :edition false) - (st/emit! (dw/end-rename-shape) - (when-not (str/empty? (str/trim name)) - (dw/update-shape (:id shape) {:name (str/trim name)}))))) + (st/emit! (dw/end-rename-shape)) + (when-not (str/empty? name) + (if main-instance? + (dwl/rename-component-and-main-instance (:component-id shape) (:id shape) name nil) + (st/emit! (dw/update-shape (:id shape) {:name name})))))) cancel-edit (fn [] (on-stop-edit) (swap! local assoc :edition false)