Skip to content

Commit

Permalink
Merge pull request #4395 from WordPress/fix/trigger-typing-mode-on-enter
Browse files Browse the repository at this point in the history
Trigger typing mode when ENTER is pressed
  • Loading branch information
noisysocks authored Jan 15, 2018
2 parents 3f54b38 + a6b45ad commit af74fa6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 0 additions & 2 deletions blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ export default class Editable extends Component {
}

event.preventDefault();
event.stopImmediatePropagation();
}

// If we click shift+Enter on inline Editables, we avoid creating two contenteditables
Expand Down Expand Up @@ -586,7 +585,6 @@ export default class Editable extends Component {
if ( event.shiftKey || ! this.props.onSplit ) {
this.editor.execCommand( 'InsertLineBreak', false, event );
} else {
event.stopImmediatePropagation();
this.splitContent();
}
}
Expand Down
19 changes: 13 additions & 6 deletions editor/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,9 @@ export class BlockListBlock extends Component {
}

maybeStartTyping() {
// We do not want to dispatch start typing if...
// - State value already reflects that we're typing (dispatch noise)
// - The current block is not selected (e.g. after a split occurs,
// we'll still receive the keyDown event, but the focus has since
// shifted to the newly created block)
if ( ! this.props.isTyping && this.props.isSelected ) {
// We do not want to dispatch start typing if state value already reflects
// that we're typing (dispatch noise)
if ( ! this.props.isTyping ) {
this.props.onStartTyping();
}
}
Expand Down Expand Up @@ -267,6 +264,10 @@ export class BlockListBlock extends Component {
} else {
onMerge( previousBlock, block );
}

// Manually trigger typing mode, since merging will remove this block and
// cause onKeyDown to not fire
this.maybeStartTyping();
}

insertBlocksAfter( blocks ) {
Expand Down Expand Up @@ -311,6 +312,9 @@ export class BlockListBlock extends Component {
createBlock( 'core/paragraph' ),
], this.props.order + 1 );
}

// Pressing enter should trigger typing mode after the content has split
this.maybeStartTyping();
break;

case UP:
Expand All @@ -336,6 +340,9 @@ export class BlockListBlock extends Component {
}
}
}

// Pressing backspace should trigger typing mode
this.maybeStartTyping();
break;

case ESCAPE:
Expand Down

0 comments on commit af74fa6

Please sign in to comment.