diff --git a/assets/src/stories-editor/blocks/amp-story-page/copy-paste-handler.js b/assets/src/stories-editor/blocks/amp-story-page/copy-paste-handler.js index c0df5b92074..77cb31f5449 100644 --- a/assets/src/stories-editor/blocks/amp-story-page/copy-paste-handler.js +++ b/assets/src/stories-editor/blocks/amp-story-page/copy-paste-handler.js @@ -20,6 +20,7 @@ function CopyPasteHandler( { children, onCopy, clientId, isSelected } ) { isFirstPage, canUserUseUnfilteredHTML, getCopiedMarkupState, + blocksOnPage, } = useSelect( ( select ) => { const { @@ -32,6 +33,7 @@ function CopyPasteHandler( { children, onCopy, clientId, isSelected } ) { isFirstPage: getBlockOrder().indexOf( clientId ) === 0, canUserUseUnfilteredHTML: __experimentalCanUserUseUnfilteredHTML, getCopiedMarkupState: getCopiedMarkup, + blocksOnPage: getBlockOrder( clientId ), }; }, [ clientId ] ); @@ -76,7 +78,7 @@ function CopyPasteHandler( { children, onCopy, clientId, isSelected } ) { } ); if ( content.length > 0 ) { - insertBlocks( ensureAllowedBlocksOnPaste( content, clientId, isFirstPage ), null, clientId ); + insertBlocks( ensureAllowedBlocksOnPaste( content, clientId, isFirstPage ), blocksOnPage.length, clientId ); } }; diff --git a/assets/src/stories-editor/components/context-menu/index.js b/assets/src/stories-editor/components/context-menu/index.js index 1c95c1c07d0..d29b754ed19 100644 --- a/assets/src/stories-editor/components/context-menu/index.js +++ b/assets/src/stories-editor/components/context-menu/index.js @@ -110,16 +110,19 @@ const ContextMenu = ( props ) => { } const isFirstPage = getBlockOrder().indexOf( pageClientId ) === 0; - insertBlocks( ensureAllowedBlocksOnPaste( content, pageClientId, isFirstPage ), null, pageClientId ).then( ( { blocks } ) => { - for ( const block of blocks ) { - if ( ALLOWED_MOVABLE_BLOCKS.includes( block.name ) ) { - updateBlockAttributes( block.clientId, { - positionTop: insidePercentageY, - positionLeft: insidePercentageX, - } ); + const blocksOnPage = getBlockOrder( pageClientId ); + insertBlocks( ensureAllowedBlocksOnPaste( content, pageClientId, isFirstPage ), blocksOnPage.length, pageClientId ) + .then( ( { blocks } ) => { + for ( const block of blocks ) { + if ( ALLOWED_MOVABLE_BLOCKS.includes( block.name ) ) { + updateBlockAttributes( block.clientId, { + positionTop: insidePercentageY, + positionLeft: insidePercentageX, + } ); + } } - } - } ).catch( () => {} ); + } ) + .catch( () => {} ); }; const cutBlock = ( clientId ) => {