Skip to content

Commit

Permalink
Single: type switching: reset the selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Mar 15, 2017
1 parent 5184632 commit e5b210d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tinymce-single/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@
getSelectedBlock: function() {
return wp.blocks.getSelectedBlocks()[0];
},
selectBlock: function( block ) {
selectBlock: function( block, _bookmark ) {
var editor = window.tinyMCE.activeEditor;
var brs = block.getElementsByTagName( 'BR' );

// Has placeholder for text.
if ( brs.length ) {
editor.selection.setCursorLocation( brs[0].parentNode, 0 );
} else if ( _bookmark ) {
editor.selection.moveToBookmark( _bookmark );
editor.focus();
} else {
editor.selection.select( block );
}
Expand Down
6 changes: 5 additions & 1 deletion tinymce-single/tinymce/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@
var currentSettings = wp.blocks.getBlockSettingsByElement( block );
var nextSettings = wp.blocks.getBlockSettings( event.control.settings.value );

editor.selection.collapse();

var bookmark = editor.selection.getBookmark();

editor.undoManager.transact( function() {
var newBlock = nextSettings.fromBaseState(
currentSettings.toBaseState( block, editor ), editor );

wp.blocks.selectBlock( newBlock );
wp.blocks.selectBlock( newBlock, bookmark );
} );
}
}
Expand Down

0 comments on commit e5b210d

Please sign in to comment.