Skip to content

Commit

Permalink
Simplify the code editor of edit-post (#52751)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 19, 2023
1 parent d27c43f commit 2c78282
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 456 deletions.
Expand Up @@ -22,10 +22,11 @@ exports[`InnerBlocks Template Sync Ensures blocks without locking are kept intac
<p class="has-large-font-size">Content…</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>added paragraph</p>
<!-- /wp:paragraph -->
<!-- /wp:test/test-inner-blocks-no-locking -->"
<!-- wp:paragraph -->
<p>added paragraph</p>
<!-- /wp:paragraph -->
<!-- /wp:test/test-inner-blocks-no-locking -->
"
`;

exports[`InnerBlocks Template Sync Removes blocks that are not expected by the template if a lock all exists 1`] = `
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-post/src/components/layout/index.js
Expand Up @@ -12,6 +12,7 @@ import {
UnsavedChangesWarning,
EditorNotices,
EditorKeyboardShortcutsRegister,
EditorKeyboardShortcuts,
EditorSnackbars,
PostSyncStatusModal,
store as editorStore,
Expand Down Expand Up @@ -203,6 +204,7 @@ function Layout( { styles } ) {
<LocalAutosaveMonitor />
<EditPostKeyboardShortcuts />
<EditorKeyboardShortcutsRegister />
<EditorKeyboardShortcuts />
<SettingsSidebar />
<InterfaceSkeleton
isDistractionFree={ isDistractionFree && isLargeViewport }
Expand Down
2 changes: 0 additions & 2 deletions packages/edit-post/src/components/text-editor/index.js
Expand Up @@ -4,7 +4,6 @@
import {
PostTextEditor,
PostTitle,
TextEditorGlobalKeyboardShortcuts,
store as editorStore,
} from '@wordpress/editor';
import { Button } from '@wordpress/components';
Expand All @@ -25,7 +24,6 @@ export default function TextEditor() {

return (
<div className="edit-post-text-editor">
<TextEditorGlobalKeyboardShortcuts />
{ isRichEditingEnabled && (
<div className="edit-post-text-editor__toolbar">
<h2>{ __( 'Editing code' ) }</h2>
Expand Down
7 changes: 1 addition & 6 deletions packages/edit-post/src/components/visual-editor/index.js
Expand Up @@ -6,11 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
VisualEditorGlobalKeyboardShortcuts,
PostTitle,
store as editorStore,
} from '@wordpress/editor';
import { PostTitle, store as editorStore } from '@wordpress/editor';
import {
WritingFlow,
BlockList,
Expand Down Expand Up @@ -345,7 +341,6 @@ export default function VisualEditor( { styles } ) {
'is-template-mode': isTemplateMode,
} ) }
>
<VisualEditorGlobalKeyboardShortcuts />
<motion.div
className="edit-post-visual-editor__content-area"
animate={ {
Expand Down
137 changes: 0 additions & 137 deletions packages/edit-site/src/components/keyboard-shortcuts/index.js

This file was deleted.

49 changes: 49 additions & 0 deletions packages/editor/src/components/global-keyboard-shortcuts/index.js
@@ -0,0 +1,49 @@
/**
* WordPress dependencies
*/
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import { useDispatch, useSelect } from '@wordpress/data';

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

export default function EditorKeyboardShortcuts() {
const { redo, undo, savePost } = useDispatch( editorStore );
const { isEditedPostDirty, isPostSavingLocked } = useSelect( editorStore );

useShortcut( 'core/editor/undo', ( event ) => {
undo();
event.preventDefault();
} );

useShortcut( 'core/editor/redo', ( event ) => {
redo();
event.preventDefault();
} );

useShortcut( 'core/editor/save', ( event ) => {
event.preventDefault();

/**
* Do not save the post if post saving is locked.
*/
if ( isPostSavingLocked() ) {
return;
}

// TODO: This should be handled in the `savePost` effect in
// considering `isSaveable`. See note on `isEditedPostSaveable`
// selector about dirtiness and meta-boxes.
//
// See: `isEditedPostSaveable`
if ( ! isEditedPostDirty() ) {
return;
}

savePost();
} );

return null;
}

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 8 additions & 2 deletions packages/editor/src/components/index.js
@@ -1,12 +1,16 @@
/**
* Internal dependencies
*/
import EditorKeyboardShortcuts from './global-keyboard-shortcuts';

// Block Creation Components.
export * from './autocompleters';

// Post Related Components.
export { default as AutosaveMonitor } from './autosave-monitor';
export { default as DocumentOutline } from './document-outline';
export { default as DocumentOutlineCheck } from './document-outline/check';
export { default as VisualEditorGlobalKeyboardShortcuts } from './global-keyboard-shortcuts/visual-editor-shortcuts';
export { default as TextEditorGlobalKeyboardShortcuts } from './global-keyboard-shortcuts/text-editor-shortcuts';
export { EditorKeyboardShortcuts };
export { default as EditorKeyboardShortcutsRegister } from './global-keyboard-shortcuts/register-shortcuts';
export { default as EditorHistoryRedo } from './editor-history/redo';
export { default as EditorHistoryUndo } from './editor-history/undo';
Expand Down Expand Up @@ -84,3 +88,5 @@ export { default as CharacterCount } from './character-count';
export { default as EditorProvider } from './provider';

export * from './deprecated';
export const VisualEditorGlobalKeyboardShortcuts = EditorKeyboardShortcuts;
export const TextEditorGlobalKeyboardShortcuts = EditorKeyboardShortcuts;

1 comment on commit 2c78282

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 2c78282.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5597917221
📝 Reported issues:

Please sign in to comment.