Skip to content

Commit

Permalink
TinyMCE per block: Fix small remaining bugs (Format toolbar and focus…
Browse files Browse the repository at this point in the history
…ing the image)
  • Loading branch information
youknowriad committed Mar 15, 2017
1 parent f44503a commit abb8e40
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tinymce-per-block/build/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tinymce-per-block/src/blocks/embed-block/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class EmbedBlockForm extends Component {

<div onClick={ () => {
api.select();
! focusConfig && api.focus();
! focusConfig && api.focus( { end: true } );
} }>
{ ! block.url &&
<div className="embed-block__form">
Expand Down
2 changes: 1 addition & 1 deletion tinymce-per-block/src/blocks/image-block/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class ImageBlockForm extends Component {
}
<div onClick={ () => {
api.select();
! focusConfig && api.focus();
! focusConfig && api.focus( { end: true } );
} }>
<img src={ block.src } className="image-block__display" />
{ ( focusConfig || block.caption ) &&
Expand Down
20 changes: 11 additions & 9 deletions tinymce-per-block/src/external/wp-blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ export default class EditableComponent extends Component {
}
}

updateContent() {
updateContent( wasFocused ) {
// This could not be called on each content change, it used to change the cursor position
let bookmark;
if ( this.props.focusConfig ) {
bookmark = this.editor.selection.getBookmark( 2, true );
}
this.editor.setContent( this.props.content );
if ( this.props.focusConfig ) {
this.editor.selection.moveToBookmark( bookmark );
if ( ! wasFocused ) {
let bookmark;
if ( this.props.focusConfig ) {
bookmark = this.editor.selection.getBookmark( 2, true );
}
this.editor.setContent( this.props.content );
if ( this.props.focusConfig ) {
this.editor.selection.moveToBookmark( bookmark );
}
}
}

Expand All @@ -76,7 +78,7 @@ export default class EditableComponent extends Component {
}

if ( this.props.content !== prevProps.content ) {
this.updateContent();
this.updateContent( !! prevProps.focusConfig );
}
}

Expand Down

0 comments on commit abb8e40

Please sign in to comment.