Skip to content

Commit

Permalink
Moving blocks should not affect the selection reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 10, 2017
1 parent 5514202 commit 7c82b00
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
9 changes: 9 additions & 0 deletions editor/block-mover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getBlockType } from '@wordpress/blocks';
import './style.scss';
import { isFirstBlock, isLastBlock, getBlockIndex, getBlock } from '../selectors';
import { getBlockMoverLabel } from './mover-label';
import { selectBlock } from '../actions';

function BlockMover( { onMoveUp, onMoveDown, isFirst, isLast, uids, blockType, firstIndex } ) {
// We emulate a disabled state because forcefully applying the `disabled`
Expand Down Expand Up @@ -68,12 +69,20 @@ export default connect(
} ),
( dispatch, ownProps ) => ( {
onMoveDown() {
if ( ownProps.uids.length === 1 ) {
dispatch( selectBlock( first( ownProps.uids ) ) );
}

dispatch( {
type: 'MOVE_BLOCKS_DOWN',
uids: ownProps.uids,
} );
},
onMoveUp() {
if ( ownProps.uids.length === 1 ) {
dispatch( selectBlock( first( ownProps.uids ) ) );
}

dispatch( {
type: 'MOVE_BLOCKS_UP',
uids: ownProps.uids,
Expand Down
11 changes: 0 additions & 11 deletions editor/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,6 @@ export function blockSelection( state = { start: null, end: null, focus: null },
end: action.blocks[ 0 ].uid,
focus: {},
};
case 'MOVE_BLOCKS_UP':
case 'MOVE_BLOCKS_DOWN': {
const firstUid = first( action.uids );
return firstUid === state.start
? state
: {
start: firstUid,
end: firstUid,
focus: {},
};
}
}

return state;
Expand Down
18 changes: 0 additions & 18 deletions editor/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,24 +734,6 @@ describe( 'state', () => {
expect( state3 ).toEqual( { start: 'ribs', end: 'ribs', focus: {} } );
} );

it( 'should return with block moved up', () => {
const state = blockSelection( undefined, {
type: 'MOVE_BLOCKS_UP',
uids: [ 'ribs' ],
} );

expect( state ).toEqual( { start: 'ribs', end: 'ribs', focus: {} } );
} );

it( 'should return with block moved down', () => {
const state = blockSelection( undefined, {
type: 'MOVE_BLOCKS_DOWN',
uids: [ 'chicken' ],
} );

expect( state ).toEqual( { start: 'chicken', end: 'chicken', focus: {} } );
} );

it( 'should not update the state if the block moved is already selected', () => {
const original = deepFreeze( { start: 'ribs', end: 'ribs', focus: {} } );
const state = blockSelection( original, {
Expand Down

0 comments on commit 7c82b00

Please sign in to comment.