Skip to content

Commit

Permalink
Fix to always paste new content on top layer (#3600)
Browse files Browse the repository at this point in the history
Make sure to paste on the top layer by using second argument of `insertBlocks` set to number of blocks on page.
  • Loading branch information
barklund authored and swissspidy committed Oct 23, 2019
1 parent faa1f8a commit 7e86f8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function CopyPasteHandler( { children, onCopy, clientId, isSelected } ) {
isFirstPage,
canUserUseUnfilteredHTML,
getCopiedMarkupState,
blocksOnPage,
} = useSelect(
( select ) => {
const {
Expand All @@ -32,6 +33,7 @@ function CopyPasteHandler( { children, onCopy, clientId, isSelected } ) {
isFirstPage: getBlockOrder().indexOf( clientId ) === 0,
canUserUseUnfilteredHTML: __experimentalCanUserUseUnfilteredHTML,
getCopiedMarkupState: getCopiedMarkup,
blocksOnPage: getBlockOrder( clientId ),
};
}, [ clientId ]
);
Expand Down Expand Up @@ -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 );
}
};

Expand Down
21 changes: 12 additions & 9 deletions assets/src/stories-editor/components/context-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => {
Expand Down

0 comments on commit 7e86f8e

Please sign in to comment.