diff --git a/editor/reducer.js b/editor/reducer.js index 9014345bb7e733..d0d2ae1681c2b4 100644 --- a/editor/reducer.js +++ b/editor/reducer.js @@ -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 ) { diff --git a/editor/test/reducer.js b/editor/test/reducer.js index a38b7ef559c223..cf5985c400ec43 100644 --- a/editor/test/reducer.js +++ b/editor/test/reducer.js @@ -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', @@ -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', () => {