-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Double click block to exit zoom out mode (#64573)
Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org>
- Loading branch information
1 parent
abf72c9
commit fae4d1b
Showing
3 changed files
with
53 additions
and
2 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
44 changes: 44 additions & 0 deletions
44
packages/block-editor/src/components/block-list/use-block-props/use-zoom-out-mode-exit.js
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,44 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useDispatch } from '@wordpress/data'; | ||
import { useRefEffect } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../../store'; | ||
import { unlock } from '../../../lock-unlock'; | ||
|
||
/** | ||
* Allows Zoom Out mode to be exited by double clicking in the selected block. | ||
* | ||
* @param {string} clientId Block client ID. | ||
*/ | ||
export function useZoomOutModeExit( { editorMode } ) { | ||
const { __unstableSetEditorMode } = unlock( | ||
useDispatch( blockEditorStore ) | ||
); | ||
|
||
return useRefEffect( | ||
( node ) => { | ||
if ( editorMode !== 'zoom-out' ) { | ||
return; | ||
} | ||
|
||
function onDoubleClick( event ) { | ||
if ( ! event.defaultPrevented ) { | ||
event.preventDefault(); | ||
__unstableSetEditorMode( 'edit' ); | ||
} | ||
} | ||
|
||
node.addEventListener( 'dblclick', onDoubleClick ); | ||
|
||
return () => { | ||
node.removeEventListener( 'dblclick', onDoubleClick ); | ||
}; | ||
}, | ||
[ editorMode, __unstableSetEditorMode ] | ||
); | ||
} |