diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index f27c794e62..a0c122dc1f 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -1515,6 +1515,16 @@ (component-sync-events state component-id file-id undo-group) [(dwu/commit-undo-transaction undo-id)])))))) +(defn- main-ancestor + "The main instance `shape` is or lies inside, through any copies nested in + it, or nil." + [objects shape] + (loop [shape shape] + (cond + (or (nil? shape) (cfh/root? shape)) nil + (ctk/main-instance? shape) shape + :else (recur (get objects (:parent-id shape)))))) + (defn- moves-whole-mains? "Whether the `changes` of a translation commit, applied on the file `data`, move only shapes outside mains, or whole mains: every shape they @@ -1524,9 +1534,9 @@ (let [objects (dm/get-in data [:pages-index page-id :objects]) ids (into #{} (map :id) changes)] (every? (fn [id] - (let [root (ctn/get-component-shape objects (get objects id) {:allow-main? true})] - (or (not (ctk/main-instance? root)) - (contains? ids (:id root))))) + (let [main (main-ancestor objects (get objects id))] + (or (nil? main) + (contains? ids (:id main))))) ids))) (group-by :page-id (filter #(= :mod-obj (:type %)) changes)))) diff --git a/frontend/test/frontend_tests/data/workspace_sync_barrier_test.cljs b/frontend/test/frontend_tests/data/workspace_sync_barrier_test.cljs index 789d36da50..bfa79d8f4c 100644 --- a/frontend/test/frontend_tests/data/workspace_sync_barrier_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_sync_barrier_test.cljs @@ -111,6 +111,16 @@ (t/is open?) (t/is (= red (ftm/fill-of :copy-child))))))) +(t/deftest translation-of-a-copy-nested-in-a-main-syncs-the-copies + ;; a copy placed in a main is part of it: moving it is an edit of the main + (t/async done + (ftm/install! (setup/nested-component-with-copy)) + (st/emit! (ftm/fill-commit :main2-nested-head red {:translation? true})) + (-> (pwrf/wait-for-layout-update nil 2000) + (.then #(t/is (= red (ftm/fill-of :copy2-child)))) + (.catch #(t/is false (str "the wait threw: " %))) + (.finally done)))) + (t/deftest derived-commit-leaves-nothing-pending (t/async done (run-commit done {:skip-component-sync? true} dropped)))