Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onReplace: select the last block #13294

Merged
merged 3 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
isEqual,
isEmpty,
overSome,
get,
} from 'lodash';

/**
Expand Down Expand Up @@ -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;

ellatrix marked this conversation as resolved.
Show resolved Hide resolved
if ( nextSelectedBlockClientId === state.start && nextSelectedBlockClientId === state.end ) {
return state;
}
Expand Down
7 changes: 6 additions & 1 deletion packages/editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,12 @@ describe( 'state', () => {
} ],
} );

expect( state ).toBe( original );
mcsf marked this conversation as resolved.
Show resolved Hide resolved
expect( state ).toEqual( {
start: 'wings',
end: 'wings',
initialPosition: null,
isMultiSelecting: false,
} );
} );

it( 'should reset if replacing with empty set', () => {
Expand Down