Skip to content

Commit

Permalink
Merge meta+a logic, fix non contenteditable, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 19, 2018
1 parent 1c39a63 commit c61c7b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
12 changes: 1 addition & 11 deletions editor/components/editor-global-keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { connect } from 'react-redux';
import { first, last } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -14,22 +13,15 @@ import { KeyboardShortcuts, withContext } from '@wordpress/components';
* Internal dependencies
*/
import { getBlockUids, getMultiSelectedBlockUids } from '../../store/selectors';
import { clearSelectedBlock, multiSelect, redo, undo, removeBlocks } from '../../store/actions';
import { clearSelectedBlock, redo, undo, removeBlocks } from '../../store/actions';

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

selectAll( event ) {
const { uids, onMultiSelect } = this.props;
event.preventDefault();
onMultiSelect( first( uids ), last( uids ) );
}

undoOrRedo( event ) {
const { onRedo, onUndo } = this.props;
if ( event.shiftKey ) {
Expand All @@ -54,7 +46,6 @@ class EditorGlobalKeyboardShortcuts extends Component {
render() {
return (
<KeyboardShortcuts shortcuts={ {
'mod+a': this.selectAll,
'mod+z': this.undoOrRedo,
'mod+shift+z': this.undoOrRedo,
backspace: this.deleteSelectedBlocks,
Expand All @@ -75,7 +66,6 @@ export default compose(
},
{
clearSelectedBlock,
onMultiSelect: multiSelect,
onRedo: redo,
onUndo: undo,
onRemove: removeBlocks,
Expand Down
15 changes: 10 additions & 5 deletions editor/components/writing-flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,23 @@ class WritingFlow extends Component {
this.props.onBottomReached();
}

// We have to check early, by the time both keys are pressed,
// selection already happened.
const activeElement = document.activeElement;

// Set right before the meta+a combination can be pressed.
if ( isMeta( event ) ) {
this.activeElementFullySelected = isFullySelected( document.activeElement );
this.isFullySelected = isFullySelected( activeElement );
}

if ( isMeta( event, 'a' ) ) {
if ( this.activeElementFullySelected ) {
// In the case of contentEditable, we want to know the earlier value
// because the selection will have already been set by TinyMCE.
if ( activeElement.isContentEditable ? this.isFullySelected : isFullySelected( activeElement ) ) {
onMultiSelect( first( blocks ), last( blocks ) );
event.preventDefault();
}

this.activeElementFullySelected = isFullySelected( document.activeElement );
// Set in case the meta key doesn't get released.
this.isFullySelected = isFullySelected( activeElement );
}
}

Expand Down

0 comments on commit c61c7b7

Please sign in to comment.