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

Focus: Fix focus jumps when splitting a text block #480

Merged
merged 1 commit into from
Apr 24, 2017
Merged
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
7 changes: 6 additions & 1 deletion blocks/components/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export default class Editable extends wp.element.Component {
this.editor.setContent( this.props.value || '' );
const hasAfter = !! childNodes.slice( splitIndex )
.reduce( ( memo, node ) => memo + node.textContent, '' );
this.props.onSplit( before, hasAfter ? after : '' );

// The setTimeout fixes the focus jump to the original block
setTimeout( () => this.props.onSplit( before, hasAfter ? after : '' ) );
}

bindNode( ref ) {
Expand All @@ -117,6 +119,9 @@ export default class Editable extends wp.element.Component {
const bookmark = this.editor.selection.getBookmark( 2, true );
this.editor.setContent( this.props.value );
this.editor.selection.moveToBookmark( bookmark );
// Saving the editor on updates avoid unecessary onChanges calls
// These calls can make the focus jump
this.editor.save();
}

focus() {
Expand Down