From c38fb24ca67c0c8cf3f84414af5413cb5200d91f Mon Sep 17 00:00:00 2001 From: iseulde Date: Tue, 14 Mar 2017 11:55:16 +0100 Subject: [PATCH 1/2] Don't clone temporary attributes on enter --- tinymce-single/tinymce/block.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tinymce-single/tinymce/block.js b/tinymce-single/tinymce/block.js index 660c6e69e40ae8..19b4e4ad9476e9 100644 --- a/tinymce-single/tinymce/block.js +++ b/tinymce-single/tinymce/block.js @@ -199,10 +199,10 @@ } } ); - editor.on( 'keyup', function( event ) { - if ( event.keyCode === tinymce.util.VK.ENTER ) { - editor.$( editor.selection.getNode() ).attr( 'data-wp-placeholder', null ); - } + editor.on( 'newBlock', function( event ) { + editor.$( event.newBlock ) + .attr( 'data-wp-placeholder', null ) + .attr( 'data-wp-block-selected', null ); } ); // Attach block UI. From 9abc4b85c176ee3f5a8b0c4922e3aab846c0b85b Mon Sep 17 00:00:00 2001 From: iseulde Date: Tue, 14 Mar 2017 12:15:37 +0100 Subject: [PATCH 2/2] Pad empty elements in case the browser deletes them on backspace --- tinymce-single/tinymce/block.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tinymce-single/tinymce/block.js b/tinymce-single/tinymce/block.js index 19b4e4ad9476e9..8badd89e3a1f5e 100644 --- a/tinymce-single/tinymce/block.js +++ b/tinymce-single/tinymce/block.js @@ -205,6 +205,18 @@ .attr( 'data-wp-block-selected', null ); } ); + editor.on( 'keyup', function( event ) { + if ( event.keyCode === tinymce.util.VK.BACKSPACE ) { + var $empty = editor.$( editor.selection.getNode() ).find( ':empty' ); + + $empty.append( '
' ); + + if ( $empty.length ) { + editor.selection.setCursorLocation( $empty[0], 0 ); + } + } + } ); + // Attach block UI. editor.on( 'preinit', function() {