Skip to content

Commit

Permalink
Remove focus on multi-select stop
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 31, 2017
1 parent 80065ba commit cf075fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions editor/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,14 @@ export function blockSelection( state = { start: null, end: null, focus: null, i
return {
...state,
isMultiSelecting: false,
focus: state.start === state.end ? state.focus : null,
};
case 'MULTI_SELECT':
return {
...state,
start: action.start,
end: action.end,
focus: state.isMultiSelecting ? state.focus : null,
};
case 'SELECT_BLOCK':
if ( action.uid === state.start && action.uid === state.end ) {
Expand Down
24 changes: 22 additions & 2 deletions editor/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,17 @@ describe( 'state', () => {
} );

it( 'should set multi selection', () => {
const original = deepFreeze( { focus: { editable: 'citation' }, isMultiSelecting: false } );
const state = blockSelection( original, {
type: 'MULTI_SELECT',
start: 'ribs',
end: 'chicken',
} );

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

it( 'should set continuous multi selection', () => {
const original = deepFreeze( { focus: { editable: 'citation' }, isMultiSelecting: true } );
const state = blockSelection( original, {
type: 'MULTI_SELECT',
Expand All @@ -761,13 +772,22 @@ describe( 'state', () => {
expect( state ).toEqual( { start: 'ribs', end: 'ribs', focus: { editable: 'citation' }, isMultiSelecting: true } );
} );

it( 'should end multi selection', () => {
it( 'should end multi selection with selection', () => {
const original = deepFreeze( { start: 'ribs', end: 'chicken', focus: { editable: 'citation' }, isMultiSelecting: true } );
const state = blockSelection( original, {
type: 'STOP_MULTI_SELECT',
} );

expect( state ).toEqual( { start: 'ribs', end: 'chicken', focus: { editable: 'citation' }, isMultiSelecting: false } );
expect( state ).toEqual( { start: 'ribs', end: 'chicken', focus: null, isMultiSelecting: false } );
} );

it( 'should end multi selection without selection', () => {
const original = deepFreeze( { start: 'ribs', end: 'ribs', focus: { editable: 'citation' }, isMultiSelecting: true } );
const state = blockSelection( original, {
type: 'STOP_MULTI_SELECT',
} );

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

it( 'should not update the state if the block is already selected', () => {
Expand Down

0 comments on commit cf075fb

Please sign in to comment.