Skip to content

Commit

Permalink
Simplify the toolbar computing
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Apr 27, 2017
1 parent 95723f3 commit e5ba308
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { connect } from 'react-redux';
import classnames from 'classnames';
import { Slot } from 'react-slot-fill';
import { reduce, last } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -139,15 +138,9 @@ class VisualEditorBlock extends wp.element.Component {
}

// Normalize controls as an array of arrays (toolbars of controls)
const toolbars = reduce( settings.controls, ( result, toolbar ) => (
Array.isArray( toolbar )
// Array entry is simply concatenated into normalized value
// Example: [ [ 1, 2 ], [ 3, 4 ] ] => [ [ 1, 2 ], [ 3, 4 ] ]
? [ ...result, toolbar ]
// Singular values are appended to the last array in the result
// Example: [ 1, 2, 3, 4 ] => [ [ 1, 2, 3, 4 ] ]
: [ ...result.slice( 0, -1 ), [ ...( last( result ) || [] ), toolbar ] ]
), [] );
const toolbars = settings.controls && settings.controls.length && ! Array.isArray( settings.controls[ 0 ] )
? [ settings.controls ]
: settings.controls;

// Disable reason: Each block can receive focus but must be able to contain
// block children. Tab keyboard navigation enabled by tabIndex assignment.
Expand Down

0 comments on commit e5ba308

Please sign in to comment.