Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Editor: Fix save shortcut #40848

Merged
merged 2 commits into from
May 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactor to use hooks
  • Loading branch information
Mamaduka committed May 5, 2022
commit db40e87a8f9c2a9c48912de87258e7554b28dc35
26 changes: 8 additions & 18 deletions packages/edit-post/src/components/text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ import {
store as editorStore,
} from '@wordpress/editor';
import { Button } from '@wordpress/components';
import { withDispatch, withSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { displayShortcut } from '@wordpress/keycodes';
import { compose } from '@wordpress/compose';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../store';

function TextEditor( { onExit, isRichEditingEnabled } ) {
export default function TextEditor() {
const isRichEditingEnabled = useSelect( ( select ) => {
return select( editorStore ).getEditorSettings().richEditingEnabled;
}, [] );
const { switchEditorMode } = useDispatch( editPostStore );

return (
<div className="edit-post-text-editor">
<TextEditorGlobalKeyboardShortcuts />
Expand All @@ -27,7 +31,7 @@ function TextEditor( { onExit, isRichEditingEnabled } ) {
<h2>{ __( 'Editing code' ) }</h2>
<Button
variant="tertiary"
onClick={ onExit }
onClick={ () => switchEditorMode( 'visual' ) }
shortcut={ displayShortcut.secondary( 'm' ) }
>
{ __( 'Exit code editor' ) }
Expand All @@ -41,17 +45,3 @@ function TextEditor( { onExit, isRichEditingEnabled } ) {
</div>
);
}

export default compose(
withSelect( ( select ) => ( {
isRichEditingEnabled: select( editorStore ).getEditorSettings()
.richEditingEnabled,
} ) ),
withDispatch( ( dispatch ) => {
return {
onExit() {
dispatch( editPostStore ).switchEditorMode( 'visual' );
},
};
} )
)( TextEditor );