From edfc2ef0f95e6202f8b7070f98ab6c975baf5657 Mon Sep 17 00:00:00 2001 From: iseulde Date: Fri, 11 Jan 2019 16:25:01 +0000 Subject: [PATCH 1/3] onReplace: select the last block --- packages/editor/src/store/reducer.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js index 06061290396de..ab3deb9469dc3 100644 --- a/packages/editor/src/store/reducer.js +++ b/packages/editor/src/store/reducer.js @@ -15,7 +15,6 @@ import { isEqual, isEmpty, overSome, - get, } from 'lodash'; /** @@ -887,9 +886,11 @@ export function blockSelection( state = { return state; } - // If there is replacement block(s), assign first's client ID as - // the next selected block. If empty replacement, reset to null. - const nextSelectedBlockClientId = get( action.blocks, [ 0, 'clientId' ], null ); + // If there are replacement blocks, assign last block as the next + // selected block, otherwise set to null. + const lastBlock = last( action.blocks ); + const nextSelectedBlockClientId = lastBlock ? lastBlock.clientId : null; + if ( nextSelectedBlockClientId === state.start && nextSelectedBlockClientId === state.end ) { return state; } From e05db07d7f7286b706c9207f106c6d346d0dc715 Mon Sep 17 00:00:00 2001 From: iseulde Date: Fri, 11 Jan 2019 16:58:08 +0000 Subject: [PATCH 2/3] Update tests --- packages/editor/src/store/test/reducer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/store/test/reducer.js b/packages/editor/src/store/test/reducer.js index 2d11a0e319a2d..0ade84dcdb283 100644 --- a/packages/editor/src/store/test/reducer.js +++ b/packages/editor/src/store/test/reducer.js @@ -1826,7 +1826,12 @@ describe( 'state', () => { } ], } ); - expect( state ).toBe( original ); + expect( state ).toEqual( { + start: 'wings', + end: 'wings', + initialPosition: null, + isMultiSelecting: false, + } ); } ); it( 'should reset if replacing with empty set', () => { From 76c3aa23cc783b153a2b5d34714be0c1c79aa4ed Mon Sep 17 00:00:00 2001 From: Miguel Fonseca Date: Mon, 18 Feb 2019 12:21:00 +0000 Subject: [PATCH 3/3] Add second test to cover cases of REPLACE_BLOCKS --- packages/editor/src/store/test/reducer.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/store/test/reducer.js b/packages/editor/src/store/test/reducer.js index 0ade84dcdb283..a8172df208a41 100644 --- a/packages/editor/src/store/test/reducer.js +++ b/packages/editor/src/store/test/reducer.js @@ -1810,7 +1810,26 @@ describe( 'state', () => { } ); } ); - it( 'should not replace the selected block if we keep it when replacing blocks', () => { + it( 'should not replace the selected block if we keep it at the end when replacing blocks', () => { + const original = deepFreeze( { start: 'wings', end: 'wings' } ); + const state = blockSelection( original, { + type: 'REPLACE_BLOCKS', + clientIds: [ 'wings' ], + blocks: [ + { + clientId: 'chicken', + name: 'core/freeform', + }, + { + clientId: 'wings', + name: 'core/freeform', + } ], + } ); + + expect( state ).toBe( original ); + } ); + + it( 'should replace the selected block if we keep it not at the end when replacing blocks', () => { const original = deepFreeze( { start: 'chicken', end: 'chicken' } ); const state = blockSelection( original, { type: 'REPLACE_BLOCKS',