From 2d4a4fb78fad23d5b0ada5074c29ad9033996ed5 Mon Sep 17 00:00:00 2001 From: iseulde Date: Tue, 14 Mar 2017 12:37:13 +0100 Subject: [PATCH 1/3] Delete empty block on backspace --- tinymce-single/tinymce/block.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tinymce-single/tinymce/block.js b/tinymce-single/tinymce/block.js index 8badd89e3a1f5..d7084fceb0e1f 100644 --- a/tinymce-single/tinymce/block.js +++ b/tinymce-single/tinymce/block.js @@ -207,16 +207,27 @@ editor.on( 'keyup', function( event ) { if ( event.keyCode === tinymce.util.VK.BACKSPACE ) { - var $empty = editor.$( editor.selection.getNode() ).find( ':empty' ); + var block = getSelectedBlock(); - $empty.append( '
' ); + console.log(block, block.textContent) - if ( $empty.length ) { - editor.selection.setCursorLocation( $empty[0], 0 ); + if ( ! block.textContent ) { + removeBlock( block ); } } } ); + function removeBlock( block ) { + var $blocks = editor.$( block || getSelectedBlock() ); + var p = editor.$( '


' ); + + editor.undoManager.transact( function() { + $blocks.first().before( p ); + editor.selection.setCursorLocation( p[0], 0 ); + $blocks.remove(); + } ); + } + // Attach block UI. editor.on( 'preinit', function() { @@ -246,17 +257,6 @@ } }); - function removeBlock() { - var $blocks = editor.$( getSelectedBlock() ); - var p = editor.$( '


' ); - - editor.undoManager.transact( function() { - $blocks.first().before( p ); - editor.selection.setCursorLocation( p[0], 0 ); - $blocks.remove(); - } ); - } - function moveBlockUp() { $blocks = editor.$( getSelectedBlocks() ); $first = $blocks.first(); From 678a1f5f4276789f5821e6da8058c4af6bb24a73 Mon Sep 17 00:00:00 2001 From: iseulde Date: Tue, 14 Mar 2017 12:37:47 +0100 Subject: [PATCH 2/3] Fix caption focus in Firefox --- tinymce-single/tinymce/block.css | 1 + 1 file changed, 1 insertion(+) diff --git a/tinymce-single/tinymce/block.css b/tinymce-single/tinymce/block.css index 82f8e5fba7262..5cbafc2629e39 100644 --- a/tinymce-single/tinymce/block.css +++ b/tinymce-single/tinymce/block.css @@ -385,4 +385,5 @@ div.mce-inline-toolbar-grp.block-toolbar > div.mce-stack-layout { content: attr(data-wp-placeholder); position: absolute; opacity: 0.5; + pointer-events: none; } From 94e87cd2b6cab23806b80015e969018064c99e5c Mon Sep 17 00:00:00 2001 From: iseulde Date: Tue, 14 Mar 2017 12:43:04 +0100 Subject: [PATCH 3/3] Don't add undo level for backspace fix --- tinymce-single/tinymce/block.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tinymce-single/tinymce/block.js b/tinymce-single/tinymce/block.js index d7084fceb0e1f..a9ebcd2ab0b1d 100644 --- a/tinymce-single/tinymce/block.js +++ b/tinymce-single/tinymce/block.js @@ -209,25 +209,16 @@ if ( event.keyCode === tinymce.util.VK.BACKSPACE ) { var block = getSelectedBlock(); - console.log(block, block.textContent) - if ( ! block.textContent ) { - removeBlock( block ); + var p = editor.$( '


' ); + + editor.$( block ).before( p ); + editor.selection.setCursorLocation( p[0], 0 ); + editor.$( block ).remove(); } } } ); - function removeBlock( block ) { - var $blocks = editor.$( block || getSelectedBlock() ); - var p = editor.$( '


' ); - - editor.undoManager.transact( function() { - $blocks.first().before( p ); - editor.selection.setCursorLocation( p[0], 0 ); - $blocks.remove(); - } ); - } - // Attach block UI. editor.on( 'preinit', function() { @@ -257,6 +248,17 @@ } }); + function removeBlock() { + var $blocks = editor.$( getSelectedBlock() ); + var p = editor.$( '


' ); + + editor.undoManager.transact( function() { + $blocks.first().before( p ); + editor.selection.setCursorLocation( p[0], 0 ); + $blocks.remove(); + } ); + } + function moveBlockUp() { $blocks = editor.$( getSelectedBlocks() ); $first = $blocks.first();