Skip to content

Commit

Permalink
Utilise indexToSelect being false as equivalent to not updating selec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
getdave committed Dec 16, 2022
1 parent f8efb0d commit 9387914
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1311,11 +1311,16 @@ function selectionHelper( state = {}, action ) {
return state;
}

const shouldNotUpdateSelection = false;

const blockToSelect =
action.blocks[ action.indexToSelect ] ||
action.blocks[ action.blocks.length - 1 ];

if ( ! blockToSelect ) {
if (
! blockToSelect ||
action.indexToSelect === shouldNotUpdateSelection
) {
return {};
}

Expand Down
24 changes: 24 additions & 0 deletions packages/block-editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,30 @@ describe( 'state', () => {
);
} );

it( 'should replace the selected block but not apply a selection when `indexToSelect` is explicitly set to `false`', () => {
const original = deepFreeze( {
selectionStart: { clientId: 'chicken' },
selectionEnd: { clientId: 'chicken' },
} );
const action = {
type: 'REPLACE_BLOCKS',
clientIds: [ 'chicken' ],
blocks: [
{ clientId: 'rigas' },
{ clientId: 'chicken' },
{ clientId: 'wings' },
],
indexToSelect: false,
};
const state = selection( original, action );
expect( state ).toEqual(
expect.objectContaining( {
selectionStart: {},
selectionEnd: {},
} )
);
} );

it( 'should reset if replacing with empty set', () => {
const original = deepFreeze( {
selectionStart: { clientId: 'chicken' },
Expand Down

1 comment on commit 9387914

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3712353915
📝 Reported issues:

Please sign in to comment.