diff --git a/editor/selectors.js b/editor/selectors.js index 48e75b611617b5..9dc5711bceb1a7 100644 --- a/editor/selectors.js +++ b/editor/selectors.js @@ -2,7 +2,7 @@ * External dependencies */ import moment from 'moment'; -import { first, last, get, values, sortBy } from 'lodash'; +import { first, last, get, values } from 'lodash'; import createSelector from 'rememo'; /** @@ -677,10 +677,6 @@ export function getNotices( state ) { * @return {Array} List of recently used blocks */ export function getRecentlyUsedBlocks( state ) { - // resolves the block names in the state to the block type settings, - // and orders by title so they don't jump around as much in the recent tab - return sortBy( - state.editor.recentlyUsedBlocks.map( blockType => getBlockType( blockType ) ), - ( blockType ) => blockType.title - ); + // resolves the block names in the state to the block type settings + return state.editor.recentlyUsedBlocks.map( blockType => getBlockType( blockType ) ); } diff --git a/editor/state.js b/editor/state.js index 8acf1d7afc8fe8..b53c47893c0f10 100644 --- a/editor/state.js +++ b/editor/state.js @@ -235,13 +235,14 @@ export const editor = combineUndoableReducers( { .filter( ( blockType ) => 'common' === blockType.category ) .slice( 0, maxRecent ) .map( ( blockType ) => blockType.name ); - case 'INSERT_BLOCK': + case 'INSERT_BLOCKS': // This is where we record the block usage so it can show up in // the recent blocks. - return [ - action.block.name, - ...without( state, action.block.name ), - ].slice( 0, maxRecent ); + let newState = [ ...state ]; + action.blocks.forEach( ( block ) => { + newState = [ block.name, ...without( newState, block.name ) ]; + } ); + return newState.slice( 0, maxRecent ); } return state; }, diff --git a/editor/test/state.js b/editor/test/state.js index d4fe949addccde..78bf877208a815 100644 --- a/editor/test/state.js +++ b/editor/test/state.js @@ -84,27 +84,26 @@ describe( 'state', () => { it( 'should record recently used blocks', () => { const original = editor( undefined, {} ); - expect( original.recentlyUsedBlocks ).to.not.include( 'core-embed/twitter' ); - const state = editor( original, { - type: 'INSERT_BLOCK', - block: { + type: 'INSERT_BLOCKS', + blocks: [ { uid: 'bacon', name: 'core-embed/twitter', - }, + } ], } ); - expect( state.recentlyUsedBlocks ).to.eql( [ 'core-embed/twitter' ] ); + expect( state.recentlyUsedBlocks[ 0 ] ).toEqual( 'core-embed/twitter' ); const twoRecentBlocks = editor( state, { - type: 'INSERT_BLOCK', - block: { + type: 'INSERT_BLOCKS', + blocks: [ { uid: 'eggs', name: 'core-embed/youtube', - }, + } ], } ); - expect( twoRecentBlocks.recentlyUsedBlocks ).to.eql( [ 'core-embed/youtube', 'core-embed/twitter' ] ); + expect( twoRecentBlocks.recentlyUsedBlocks[ 0 ] ).toEqual( 'core-embed/youtube' ); + expect( twoRecentBlocks.recentlyUsedBlocks[ 1 ] ).toEqual( 'core-embed/twitter' ); } ); it( 'should populate recently used blocks with the common category', () => { @@ -116,7 +115,7 @@ describe( 'state', () => { }, } ); - expect( initial.recentlyUsedBlocks ).to.have.eql( [ 'core/test-block' ] ); + expect( initial.recentlyUsedBlocks ).toEqual( expect.arrayContaining( [ 'core/test-block', 'core/text' ] ) ); } ); it( 'should replace the block', () => {