Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ function GalleryEdit( props ) {
return file;
} );

// Because we are reusing existing innerImage blocks any reordering
// done in the media libary will be lost so we need to reapply that ordering
// once the new image blocks are merged in with existing.
const newOrderMap = processedImages.reduce(
( result, image, index ) => (
( result[ image.id ] = index ), result
),
{}
);

const existingImageBlocks = ! newFileUploads
? innerBlockImages.filter( ( block ) =>
processedImages.find(
Expand All @@ -255,7 +265,11 @@ function GalleryEdit( props ) {

replaceInnerBlocks(
clientId,
concat( existingImageBlocks, newBlocks )
concat( existingImageBlocks, newBlocks ).sort(
( a, b ) =>
newOrderMap[ a.attributes.id ] -
newOrderMap[ b.attributes.id ]
)
);
}

Expand Down