-
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.
Improve the performance of the keyboard shortcuts binding (#23394)
- Loading branch information
1 parent
a41914a
commit 2f427af
Showing
3 changed files
with
24 additions
and
38 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
33 changes: 9 additions & 24 deletions
33
packages/block-editor/src/components/rich-text/shortcut.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 |
---|---|---|
@@ -1,32 +1,17 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { KeyboardShortcuts } from '@wordpress/components'; | ||
import { useKeyboardShortcut } from '@wordpress/compose'; | ||
import { rawShortcut } from '@wordpress/keycodes'; | ||
|
||
export class RichTextShortcut extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.onUse = this.onUse.bind( this ); | ||
} | ||
|
||
onUse() { | ||
this.props.onUse(); | ||
export function RichTextShortcut( { character, type, onUse } ) { | ||
const callback = () => { | ||
onUse(); | ||
return false; | ||
} | ||
|
||
render() { | ||
const { character, type } = this.props; | ||
}; | ||
useKeyboardShortcut( rawShortcut[ type ]( character ), callback, { | ||
bindGlobal: true, | ||
} ); | ||
|
||
return ( | ||
<KeyboardShortcuts | ||
bindGlobal | ||
shortcuts={ { | ||
[ rawShortcut[ type ]( character ) ]: this.onUse, | ||
} } | ||
/> | ||
); | ||
} | ||
return null; | ||
} |
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