Skip to content

Commit

Permalink
Show UI on text selection (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored May 23, 2017
1 parent 3f2be75 commit 5781400
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,18 @@ export default class Editable extends wp.element.Component {
}

const content = this.getContent();
const collapsed = this.editor.selection.isCollapsed();

this.setState( {
empty: ! content || ! content.length,
} );

if ( this.props.focus.collapsed !== collapsed ) {
this.props.onFocus( {
...this.props.focus,
collapsed,
} );
}
}

onChange() {
Expand Down
7 changes: 4 additions & 3 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ class VisualEditorBlock extends wp.element.Component {
}

const { isHovered, isSelected, isTyping, focus } = this.props;
const showUI = isSelected && ( ! isTyping || ! focus.collapsed );
const className = classnames( 'editor-visual-editor__block', {
'is-selected': isSelected && ! isTyping,
'is-selected': showUI,
'is-hovered': isHovered,
} );

Expand Down Expand Up @@ -196,8 +197,8 @@ class VisualEditorBlock extends wp.element.Component {
tabIndex="0"
{ ...wrapperProps }
>
{ ( ( isSelected && ! isTyping ) || isHovered ) && <BlockMover uid={ block.uid } /> }
{ isSelected && ! isTyping &&
{ ( showUI || isHovered ) && <BlockMover uid={ block.uid } /> }
{ showUI &&
<div className="editor-visual-editor__block-controls">
<BlockSwitcher uid={ block.uid } />
{ !! settings.controls && (
Expand Down

0 comments on commit 5781400

Please sign in to comment.