From 394c89be962300f2f0fc1c9dcac608b5d08058d2 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Thu, 11 Jan 2018 15:50:22 +1100 Subject: [PATCH 1/2] Trigger typing mode when ENTER is pressed Splitting a block or inserting a new paragraph block by pressing ENTER should engage typing mode. --- blocks/editable/index.js | 1 - editor/components/block-list/block.js | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/blocks/editable/index.js b/blocks/editable/index.js index 497bfa51305b86..654dadd36df8f5 100644 --- a/blocks/editable/index.js +++ b/blocks/editable/index.js @@ -586,7 +586,6 @@ export default class Editable extends Component { if ( event.shiftKey || ! this.props.onSplit ) { this.editor.execCommand( 'InsertLineBreak', false, event ); } else { - event.stopImmediatePropagation(); this.splitContent(); } } diff --git a/editor/components/block-list/block.js b/editor/components/block-list/block.js index 529e9e082f6504..c122259c48c388 100644 --- a/editor/components/block-list/block.js +++ b/editor/components/block-list/block.js @@ -223,12 +223,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(); } } @@ -310,6 +307,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: From a6b45ad634192c08237e33b954d0a7bc4b71d200 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 12 Jan 2018 12:01:43 +1100 Subject: [PATCH 2/2] Trigger typing mode when BACKSPACE is pressed --- blocks/editable/index.js | 1 - editor/components/block-list/block.js | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/blocks/editable/index.js b/blocks/editable/index.js index 654dadd36df8f5..a225c4162b2db7 100644 --- a/blocks/editable/index.js +++ b/blocks/editable/index.js @@ -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 diff --git a/editor/components/block-list/block.js b/editor/components/block-list/block.js index c122259c48c388..f8d6dca5d8c206 100644 --- a/editor/components/block-list/block.js +++ b/editor/components/block-list/block.js @@ -263,6 +263,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 ) { @@ -335,6 +339,9 @@ export class BlockListBlock extends Component { } } } + + // Pressing backspace should trigger typing mode + this.maybeStartTyping(); break; case ESCAPE: