From 56bc70dffecc3ff980c184ab0e9a8fd8694f8ed5 Mon Sep 17 00:00:00 2001
From: Alejandro Alonso <alejandroalonsofernandez@gmail.com>
Date: Tue, 12 Mar 2024 12:43:42 +0100
Subject: [PATCH] :bug: Fix restore component

---
 frontend/src/app/main/data/workspace/libraries_helpers.cljs | 3 ---
 frontend/src/app/main/data/workspace/selection.cljs         | 2 ++
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs
index 296cd7c92..8f3def937 100644
--- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs
+++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs
@@ -263,9 +263,6 @@
          parent            (get-in page [:objects parent-id])
          main-inst         (get-in component [:objects (:main-instance-id component)])
          inside-component? (some? (ctn/get-instance-root (:objects page) parent))
-         origin-frame      (get-in page [:objects (:frame-id main-inst)])
-         ;; We are using a deleted component andit's coordenates are absolute, we must adjust them to its containing frame to adjust the delta
-         delta             (gpt/subtract delta (-> origin-frame :selrect gpt/point))
          shapes            (cfh/get-children-with-self (:objects component) (:main-instance-id component))
          shapes            (map #(gsh/move % delta) shapes)
 
diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs
index 15d3d5ab4..bf1d68e44 100644
--- a/frontend/src/app/main/data/workspace/selection.cljs
+++ b/frontend/src/app/main/data/workspace/selection.cljs
@@ -433,6 +433,8 @@
         main-component    (ctf/get-component libraries file-id component-id)
         moved-component   (gsh/move component-root delta)
         pos               (gpt/point (:x moved-component) (:y moved-component))
+        origin-frame      (get-in page [:objects frame-id])
+        delta             (gpt/subtract delta (-> origin-frame :selrect gpt/point))
 
         instantiate-component
         #(dwlh/generate-instantiate-component changes