-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block Editor: Reimplement removeBlocks previous selection as control
- Loading branch information
Showing
6 changed files
with
136 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createRegistryControl } from '@wordpress/data'; | ||
|
||
export const SELECT_NEXT_BLOCK = createRegistryControl( ( registry ) => ( action ) => { | ||
const { clientId, isReverse } = action; | ||
const { | ||
getPreviousBlockClientId, | ||
getNextBlockClientId, | ||
getSelectedBlockClientId, | ||
} = registry.select( 'core/editor' ); | ||
|
||
let targetClientId; | ||
if ( isReverse ) { | ||
targetClientId = getPreviousBlockClientId( clientId ); | ||
} else { | ||
targetClientId = getNextBlockClientId( clientId ); | ||
} | ||
|
||
// Only dispatch select block action if the currently selected block is | ||
// is not already the block we want to be selected. | ||
if ( ! targetClientId || targetClientId === getSelectedBlockClientId() ) { | ||
return; | ||
} | ||
|
||
// When selecting in reverse, invert the default focus transition | ||
// behavior, selecting the last available focusable. | ||
let initialPosition; | ||
if ( isReverse ) { | ||
initialPosition = -1; | ||
} | ||
|
||
const { selectBlock } = registry.dispatch( 'core/editor' ); | ||
selectBlock( targetClientId, initialPosition ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters