-
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.
- Loading branch information
Showing
5 changed files
with
169 additions
and
65 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
45 changes: 45 additions & 0 deletions
45
packages/editor/src/components/rich-text/remove-browser-shortcuts.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,45 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { fromPairs } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { rawShortcut } from '@wordpress/keycodes'; | ||
import { KeyboardShortcuts } from '@wordpress/components'; | ||
|
||
/** | ||
* Set of keyboard shortcuts handled internally by RichText. | ||
* | ||
* @type {Array} | ||
*/ | ||
const HANDLED_SHORTCUTS = [ | ||
rawShortcut.primary( 'z' ), | ||
rawShortcut.primaryShift( 'z' ), | ||
rawShortcut.primary( 'y' ), | ||
]; | ||
|
||
/** | ||
* An instance of a KeyboardShortcuts element pre-bound for the handled | ||
* shortcuts. Since shortcuts never change, the element can be considered | ||
* static, and can be skipped in reconciliation. | ||
* | ||
* @type {WPElement} | ||
*/ | ||
const SHORTCUTS_ELEMENT = ( | ||
<KeyboardShortcuts | ||
bindGlobal | ||
shortcuts={ fromPairs( HANDLED_SHORTCUTS.map( ( shortcut ) => { | ||
return [ shortcut, ( event ) => event.preventDefault() ]; | ||
} ) ) } | ||
/> | ||
); | ||
|
||
/** | ||
* Component which registered keyboard event handlers to prevent default | ||
* behaviors for key combinations otherwise handled internally by RichText. | ||
* | ||
* @return {WPElement} WordPress element. | ||
*/ | ||
export const RemoveBrowserShortcuts = () => SHORTCUTS_ELEMENT; |
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