From a3bdbec15a8467e8df6dfee42ffa5562ce36db94 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 2 Mar 2017 10:09:34 -0500 Subject: [PATCH] Ensure current focused node is eligible for control --- tinymce-single/tinymce/block.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tinymce-single/tinymce/block.js b/tinymce-single/tinymce/block.js index 27798650f03872..713122b6f949b5 100644 --- a/tinymce-single/tinymce/block.js +++ b/tinymce-single/tinymce/block.js @@ -10,6 +10,17 @@ // Global controls + function isNodeEligibleForControl( node, name ) { + var block; + + if ( ! node ) { + return false; + } + + block = wp.blocks.getBlockSettingsByElement( node ); + return block && _.includes( block.controls, name ); + } + _.forEach( wp.blocks.getControls(), function( control, name ) { var settings = { icon: control.icon @@ -27,7 +38,9 @@ var button = this; editor.on( 'nodechange', function() { - button.active( control.isActive( element ) ); + if ( isNodeEligibleForControl( element, name ) ) { + button.active( control.isActive( element ) ); + } } ); }; }