From ba408b73bc23a470bab41a5a1b952c4d617ca6a8 Mon Sep 17 00:00:00 2001 From: iseulde Date: Wed, 1 Mar 2017 16:46:08 +0100 Subject: [PATCH 1/2] Remove delete button, delete block on backspace correctly --- tinymce-single/tinymce/block.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tinymce-single/tinymce/block.js b/tinymce-single/tinymce/block.js index 7a2fe6cc30d242..dcff6669b9eba7 100644 --- a/tinymce-single/tinymce/block.js +++ b/tinymce-single/tinymce/block.js @@ -348,7 +348,7 @@ if ( settings ) { if ( ! blockToolbars[ settings._id ] ) { - blockToolbars[ settings._id ] = editor.wp._createToolbar( settings.buttons.concat( [ 'block-remove' ] ) ); + blockToolbars[ settings._id ] = editor.wp._createToolbar( settings.buttons ); blockToolbars[ settings._id ].reposition = function () { if (!element) return @@ -553,6 +553,24 @@ event.preventDefault(); } } + } else { + if ( keyCode === VK.BACKSPACE ) { + var selection = window.getSelection(); + + if ( ! selection.isCollapsed ) { + if ( selection.anchorOffset === 0 && selection.focusOffset === 0 ) { + if ( element.nextSibling && element.nextSibling.contains( selection.focusNode ) ) { + removeBlock(); + event.preventDefault(); + } + } + + if ( selection.anchorOffset === 0 && selection.anchorNode === selection.focusNode ) { + removeBlock(); + event.preventDefault(); + } + } + } } if ( VK.metaKeyPressed( event ) ) { From 88c8e7073dd16ae885279f6cc2ac67c7deffa082 Mon Sep 17 00:00:00 2001 From: iseulde Date: Wed, 1 Mar 2017 16:55:05 +0100 Subject: [PATCH 2/2] Make sure focusnode is block before deleting whole block --- tinymce-single/tinymce/block.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinymce-single/tinymce/block.js b/tinymce-single/tinymce/block.js index dcff6669b9eba7..0961dcd4c858ff 100644 --- a/tinymce-single/tinymce/block.js +++ b/tinymce-single/tinymce/block.js @@ -557,7 +557,7 @@ if ( keyCode === VK.BACKSPACE ) { var selection = window.getSelection(); - if ( ! selection.isCollapsed ) { + if ( ! selection.isCollapsed && editor.dom.isBlock( selection.focusNode ) ) { if ( selection.anchorOffset === 0 && selection.focusOffset === 0 ) { if ( element.nextSibling && element.nextSibling.contains( selection.focusNode ) ) { removeBlock();