-
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.
Fix the editor save keyboard shortcut not working in code editor view (…
…#13159) * Fix the editor save keyboard shortcut not working in code editor view * Refactor based on code review feedback - Introduce new TextEditorGlobalShortcuts component that implements the save shortcut - Rename EditorGlobalShortcuts to VisualEditorGlobalShortcuts - Add a deprecated version of EditorGlobalShortcuts - Update CHANGELOG
- Loading branch information
Showing
9 changed files
with
103 additions
and
36 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
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
52 changes: 52 additions & 0 deletions
52
packages/editor/src/components/global-keyboard-shortcuts/save-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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { KeyboardShortcuts } from '@wordpress/components'; | ||
import { rawShortcut } from '@wordpress/keycodes'; | ||
import { compose } from '@wordpress/compose'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
|
||
export function SaveShortcut( { onSave } ) { | ||
return ( | ||
<KeyboardShortcuts | ||
bindGlobal | ||
shortcuts={ { | ||
[ rawShortcut.primary( 's' ) ]: ( event ) => { | ||
event.preventDefault(); | ||
onSave(); | ||
}, | ||
} } | ||
/> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => { | ||
const { isEditedPostDirty } = select( 'core/editor' ); | ||
|
||
return { | ||
isDirty: isEditedPostDirty(), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch, ownProps, { select } ) => { | ||
const { | ||
savePost, | ||
} = dispatch( 'core/editor' ); | ||
|
||
return { | ||
onSave() { | ||
// TODO: This should be handled in the `savePost` effect in | ||
// considering `isSaveable`. See note on `isEditedPostSaveable` | ||
// selector about dirtiness and meta-boxes. | ||
// | ||
// See: `isEditedPostSaveable` | ||
const { isEditedPostDirty } = select( 'core/editor' ); | ||
if ( ! isEditedPostDirty() ) { | ||
return; | ||
} | ||
|
||
savePost(); | ||
}, | ||
}; | ||
} ), | ||
] )( SaveShortcut ); |
10 changes: 10 additions & 0 deletions
10
packages/editor/src/components/global-keyboard-shortcuts/text-editor-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,10 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import SaveShortcut from './save-shortcut'; | ||
|
||
export default function TextEditorGlobalKeyboardShortcuts() { | ||
return ( | ||
<SaveShortcut /> | ||
); | ||
} |
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