-
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.
Writing flow: restore click redirect between blocks
- Loading branch information
Showing
5 changed files
with
37 additions
and
13 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
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
22 changes: 22 additions & 0 deletions
22
packages/block-editor/src/components/writing-flow/use-click-redirect.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,22 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRefEffect } from '@wordpress/compose'; | ||
|
||
export default function useClickSelection() { | ||
return useRefEffect( ( node ) => { | ||
function onMouseDown() { | ||
node.contentEditable = true; | ||
// Firefox doesn't automatically move focus. | ||
node.focus(); | ||
// The selection observer will turn off contentEditable after a | ||
// selection change. | ||
} | ||
|
||
node.addEventListener( 'mousedown', onMouseDown ); | ||
|
||
return () => { | ||
node.removeEventListener( 'mousedown', onMouseDown ); | ||
}; | ||
}, [] ); | ||
} |