From 210fc143ee6c04d32b29c9bd6ba555a4c7cf8506 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 15 Jul 2022 10:36:53 +0100 Subject: [PATCH] Fix pasting inside different screens and select new screen when pasting inside different screen --- packages/builder/src/builderStore/store/frontend.js | 9 ++++++--- .../screens/_components/ScreenDropdownMenu.svelte | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index ed79d8edfe..58d803aa03 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -583,7 +583,7 @@ export const getFrontendStore = () => { } } }, - paste: async (targetComponent, mode) => { + paste: async (targetComponent, mode, targetScreen) => { const state = get(store) if (!state.componentToPaste) { return @@ -591,7 +591,7 @@ export const getFrontendStore = () => { let newComponentId // Patch screen - await store.actions.screens.patch(screen => { + const patch = screen => { // Get up to date ref to target targetComponent = findComponent(screen.props, targetComponent._id) if (!targetComponent) { @@ -640,13 +640,16 @@ export const getFrontendStore = () => { const index = mode === "above" ? targetIndex : targetIndex + 1 parent._children.splice(index, 0, componentToPaste) } - }) + } + const targetScreenId = targetScreen?._id || state.selectedScreenId + await store.actions.screens.patch(patch, targetScreenId) store.update(state => { // Remove copied component if cutting if (state.componentToPaste.isCut) { delete state.componentToPaste } + state.selectedScreenId = targetScreenId state.selectedComponentId = newComponentId return state }) diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenDropdownMenu.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenDropdownMenu.svelte index 6d27ccc60b..8097291952 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenDropdownMenu.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/screens/_components/ScreenDropdownMenu.svelte @@ -23,7 +23,7 @@ const pasteComponent = mode => { try { - store.actions.components.paste(screen.props, mode) + store.actions.components.paste(screen.props, mode, screen) } catch (error) { notifications.error("Error saving component") }