Skip to content

Commit

Permalink
Renames parent selection boolean param and improves docs (#48677)
Browse files Browse the repository at this point in the history
* Renames parent selection boolean param and improves docs

Co-authored-by: Nik Tsekouras <16275880+ntsekouras@users.noreply.github.com>
Co-authored-by: George Mamadashvili <240569+Mamaduka@users.noreply.github.com>

* better wording for action docs

---------

Co-authored-by: Nik Tsekouras <16275880+ntsekouras@users.noreply.github.com>
Co-authored-by: George Mamadashvili <240569+Mamaduka@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 2, 2023
1 parent aa0f3fd commit d9aede8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ the set of specified client IDs are to be removed.
_Parameters_

- _clientIds_ `string|string[]`: Client IDs of blocks to remove.
- _selectPrevious_ `boolean`: True if the previous block should be selected when a block is removed.
- _selectPrevious_ `boolean`: True if the previous block or the immediate parent (if no previous block exists) should be selected when a block is removed.

### replaceBlock

Expand Down Expand Up @@ -1502,7 +1502,7 @@ should be selected.
_Parameters_

- _clientId_ `string`: Block client ID.
- _orFirstParent_ `boolean`: If true, select the first parent if there is no previous block.
- _fallbackToParent_ `boolean`: If true, select the first parent if there is no previous block.

### setBlockMovingClientId

Expand Down
18 changes: 10 additions & 8 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,17 @@ export function selectBlock( clientId, initialPosition = 0 ) {
* clientId (or optionally, its first parent from bottom to top)
* should be selected.
*
* @param {string} clientId Block client ID.
* @param {boolean} orFirstParent If true, select the first parent if there is no previous block.
* @param {string} clientId Block client ID.
* @param {boolean} fallbackToParent If true, select the first parent if there is no previous block.
*/
export const selectPreviousBlock =
( clientId, orFirstParent = false ) =>
( clientId, fallbackToParent = false ) =>
( { select, dispatch } ) => {
const previousBlockClientId =
select.getPreviousBlockClientId( clientId );
if ( previousBlockClientId ) {
dispatch.selectBlock( previousBlockClientId, -1 );
} else if ( orFirstParent ) {
} else if ( fallbackToParent ) {
const firstParentClientId = select.getBlockRootClientId( clientId );
if ( firstParentClientId ) {
dispatch.selectBlock( firstParentClientId, -1 );
Expand Down Expand Up @@ -1182,8 +1182,11 @@ export const mergeBlocks =
* the set of specified client IDs are to be removed.
*
* @param {string|string[]} clientIds Client IDs of blocks to remove.
* @param {boolean} selectPrevious True if the previous block should be
* selected when a block is removed.
* @param {boolean} selectPrevious True if the previous block
* or the immediate parent
* (if no previous block exists)
* should be selected
* when a block is removed.
*/
export const removeBlocks =
( clientIds, selectPrevious = true ) =>
Expand All @@ -1204,8 +1207,7 @@ export const removeBlocks =
}

if ( selectPrevious ) {
const shouldSelectParent = true;
dispatch.selectPreviousBlock( clientIds[ 0 ], shouldSelectParent );
dispatch.selectPreviousBlock( clientIds[ 0 ], selectPrevious );
}

dispatch( { type: 'REMOVE_BLOCKS', clientIds } );
Expand Down

1 comment on commit d9aede8

@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 in d9aede8.
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/4313995538
📝 Reported issues:

Please sign in to comment.