Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger typing mode when ENTER is pressed #4395

Merged
merged 2 commits into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? it was added here #3917 by @mcsf (Trying to see if this introduces any regression)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I can't spot regressions by removing that line. It should be necessary, per #3867. I wonder if something changed in the stack, e.g. some of these operations happening with deferring?

Copy link
Member Author

@noisysocks noisysocks Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding some related PRs. I'd say that if there's no regressions then we're fine to remove this line. It's a necessary change for this PR because, if we stop the event from propagating, it won't bubble up to block.js and so maybeStartTyping() won't be called when ENTER is pressed.

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 @@ -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();
}
}
Expand Down Expand Up @@ -266,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 ) {
Expand Down Expand Up @@ -310,6 +311,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 @@ -335,6 +339,9 @@ export class BlockListBlock extends Component {
}
}
}

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

case ESCAPE:
Expand Down