Skip to content

Commit

Permalink
Keyboard Shortcuts: Bind Cmd/Ctrl+S as save (#2863)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth authored Feb 16, 2018
1 parent 2b9bc80 commit b7ecf95
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions editor/components/editor-global-keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@ import { first, last } from 'lodash';
/**
* WordPress dependencies
*/
import { Component, compose } from '@wordpress/element';
import { Component, Fragment, compose } from '@wordpress/element';
import { KeyboardShortcuts, withContext } from '@wordpress/components';

/**
* Internal dependencies
*/
import { getBlockOrder, getMultiSelectedBlockUids } from '../../store/selectors';
import { clearSelectedBlock, multiSelect, redo, undo, removeBlocks } from '../../store/actions';
import {
clearSelectedBlock,
multiSelect,
redo,
undo,
autosave,
removeBlocks,
} from '../../store/actions';

class EditorGlobalKeyboardShortcuts extends Component {
constructor() {
super( ...arguments );
this.selectAll = this.selectAll.bind( this );
this.undoOrRedo = this.undoOrRedo.bind( this );
this.save = this.save.bind( this );
this.deleteSelectedBlocks = this.deleteSelectedBlocks.bind( this );
}

Expand All @@ -41,6 +49,11 @@ class EditorGlobalKeyboardShortcuts extends Component {
event.preventDefault();
}

save( event ) {
event.preventDefault();
this.props.onSave();
}

deleteSelectedBlocks( event ) {
const { multiSelectedBlockUids, onRemove, isLocked } = this.props;
if ( multiSelectedBlockUids.length ) {
Expand All @@ -53,14 +66,24 @@ class EditorGlobalKeyboardShortcuts extends Component {

render() {
return (
<KeyboardShortcuts shortcuts={ {
'mod+a': this.selectAll,
'mod+z': this.undoOrRedo,
'mod+shift+z': this.undoOrRedo,
backspace: this.deleteSelectedBlocks,
del: this.deleteSelectedBlocks,
escape: this.props.clearSelectedBlock,
} } />
<Fragment>
<KeyboardShortcuts
shortcuts={ {
'mod+a': this.selectAll,
'mod+z': this.undoOrRedo,
'mod+shift+z': this.undoOrRedo,
backspace: this.deleteSelectedBlocks,
del: this.deleteSelectedBlocks,
escape: this.props.clearSelectedBlock,
} }
/>
<KeyboardShortcuts
bindGlobal
shortcuts={ {
'mod+s': this.save,
} }
/>
</Fragment>
);
}
}
Expand All @@ -79,6 +102,7 @@ export default compose(
onRedo: redo,
onUndo: undo,
onRemove: removeBlocks,
onSave: autosave,
}
),
withContext( 'editor' )( ( settings ) => {
Expand Down

0 comments on commit b7ecf95

Please sign in to comment.