Skip to content

Commit

Permalink
Refactor based on code review feedback
Browse files Browse the repository at this point in the history
- Introduce new TextEditorGlobalShortcuts component that implements the save shortcut
- Rename EditorGlobalShortcuts to VisualEditorGlobalShortcuts
- Add a deprecated version of EditorGlobalShortcuts
- Update CHANGELOG
  • Loading branch information
talldan committed Feb 1, 2019
1 parent 4347f89 commit eed9e67
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 19 deletions.
8 changes: 6 additions & 2 deletions packages/edit-post/src/components/text-editor/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { PostTextEditor, PostTitle, EditorSaveKeyboardShortcut } from '@wordpress/editor';
import {
PostTextEditor,
PostTitle,
TextEditorGlobalKeyboardShortcuts,
} from '@wordpress/editor';
import { IconButton } from '@wordpress/components';
import { withDispatch, withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
Expand All @@ -21,7 +25,7 @@ function TextEditor( { onExit, isRichEditingEnabled } ) {
>
{ __( 'Exit Code Editor' ) }
</IconButton>
<EditorSaveKeyboardShortcut />
<TextEditorGlobalKeyboardShortcuts />
</div>
) }
<div className="edit-post-text-editor__body">
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PostTitle,
WritingFlow,
ObserveTyping,
EditorGlobalKeyboardShortcuts,
VisualEditorGlobalKeyboardShortcuts,
BlockSelectionClearer,
MultiSelectScrollIntoView,
_BlockSettingsMenuFirstItem,
Expand All @@ -23,7 +23,7 @@ import PluginBlockSettingsMenuGroup from '../block-settings-menu/plugin-block-se
function VisualEditor() {
return (
<BlockSelectionClearer className="edit-post-visual-editor editor-styles-wrapper">
<EditorGlobalKeyboardShortcuts />
<VisualEditorGlobalKeyboardShortcuts />
<CopyHandler />
<MultiSelectScrollIntoView />
<WritingFlow>
Expand Down
11 changes: 6 additions & 5 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
## 9.1.0 (Unreleased)

### New Feature
### New Features

- Added `createCustomColorsHOC` for creating a higher order `withCustomColors` component.
- Added a new `TextEditorGlobalKeyboardShortcuts` component.

### Bug Fixes
### Deprecations

- BlockSwitcher will now consistently render an icon for block multi-selections.
- `EditorGlobalKeyboardShortcuts` has been deprecated in favor of `VisualEditorGlobalKeyboardShortcuts`.

### New feature
### Bug Fixes

- Added new `EditorSaveKeyboardShortcut` component, which was refactored out from the `EditorGlobalKeyboardShortcuts` component.
- BlockSwitcher will now consistently render an icon for block multi-selections.

### Internal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { withDispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { shortcuts } from '../editor-global-keyboard-shortcuts';
import { shortcuts } from '../global-keyboard-shortcuts/visual-editor-shortcuts';
import BlockActions from '../block-actions';
import BlockModeToggle from './block-mode-toggle';
import ReusableBlockConvertButton from './reusable-block-convert-button';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { rawShortcut } from '@wordpress/keycodes';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';

export function EditorSaveKeyboardShortcut( { onSave } ) {
export function SaveShortcut( { onSave } ) {
return (
<KeyboardShortcuts
bindGlobal
Expand Down Expand Up @@ -49,4 +49,4 @@ export default compose( [
},
};
} ),
] )( EditorSaveKeyboardShortcut );
] )( SaveShortcut );
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 />
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import { KeyboardShortcuts } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { rawShortcut, displayShortcut } from '@wordpress/keycodes';
import { compose } from '@wordpress/compose';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
*/
import BlockActions from '../block-actions';
import EditorSaveKeyboardShortcut from './editor-save-keyboard-shortcut';
import SaveShortcut from './save-shortcut';

const preventDefault = ( event ) => {
event.preventDefault();
Expand All @@ -42,7 +43,7 @@ export const shortcuts = {
},
};

class EditorGlobalKeyboardShortcuts extends Component {
class VisualEditorGlobalKeyboardShortcuts extends Component {
constructor() {
super( ...arguments );

Expand Down Expand Up @@ -105,7 +106,7 @@ class EditorGlobalKeyboardShortcuts extends Component {
escape: this.clearMultiSelection,
} }
/>
<EditorSaveKeyboardShortcut />
<SaveShortcut />
{ selectedBlockClientIds.length > 0 && (
<BlockActions clientIds={ selectedBlockClientIds }>
{ ( { onDuplicate, onRemove, onInsertAfter, onInsertBefore } ) => (
Expand Down Expand Up @@ -136,7 +137,7 @@ class EditorGlobalKeyboardShortcuts extends Component {
}
}

export default compose( [
const EnhancedVisualEditorGlobalKeyboardShortcuts = compose( [
withSelect( ( select ) => {
const {
getBlockOrder,
Expand Down Expand Up @@ -176,4 +177,15 @@ export default compose( [
onRemove: removeBlocks,
};
} ),
] )( EditorGlobalKeyboardShortcuts );
] )( VisualEditorGlobalKeyboardShortcuts );

export default EnhancedVisualEditorGlobalKeyboardShortcuts;

export function EditorGlobalKeyboardShortcuts() {
deprecated( 'EditorGlobalKeyboardShortcuts', {
alternative: 'VisualEditorGlobalKeyboardShortcuts',
plugin: 'Gutenberg',
} );

return <EnhancedVisualEditorGlobalKeyboardShortcuts />;
}
7 changes: 5 additions & 2 deletions packages/editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ export { default as URLPopover } from './url-popover';
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 EditorGlobalKeyboardShortcuts } from './editor-global-keyboard-shortcuts';
export { default as EditorSaveKeyboardShortcut } from './editor-global-keyboard-shortcuts/editor-save-keyboard-shortcut';
export {
default as VisualEditorGlobalKeyboardShortcuts,
EditorGlobalKeyboardShortcuts,
} from './global-keyboard-shortcuts/visual-editor-shortcuts';
export { default as TextEditorGlobalKeyboardShortcuts } from './global-keyboard-shortcuts/text-editor-shortcuts';
export { default as EditorHistoryRedo } from './editor-history/redo';
export { default as EditorHistoryUndo } from './editor-history/undo';
export { default as EditorNotices } from './editor-notices';
Expand Down

0 comments on commit eed9e67

Please sign in to comment.