Bold button gets unchecked on enter click when bullet button is also selected in WP Editor

Question

I am using wp_edior.

Here is the scenario :

  1. Click bold, italic, bullets and write 1 line.
  2. Now press enter

Bold and italic buttons gets unchecked.

enter image description here

I tried below solution but it did not work for me.

add_filter( 'tiny_mce_before_init', 'wpse24113_tiny_mce_before_init' );
function wpse24113_tiny_mce_before_init( $initArray )
{
    $initArray['setup'] = <<<JS
[function(ed) {
    ed.onKeyDown.add(function(ed, e) {
        //your function goes here
        console.log('Key down event: ' + e.keyCode);
        if($(".mce-container.mce-btn-group .mce-btn:nth-child(2)").hasClass("mce-active") && (e.keyCode == 13)){
            console.log("active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(2)").addClass("mce-active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(2)").attr("aria-pressed","true");
        }
        if($(".mce-container.mce-btn-group .mce-btn:nth-child(3)").hasClass("mce-active") && (e.keyCode == 13)){
            console.log("active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(3)").addClass("mce-active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(3)").attr("aria-pressed","true");
        }
        if($(".mce-container.mce-btn-group .mce-btn:nth-child(4)").hasClass("mce-active") && (e.keyCode == 13)){
            console.log("active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(4)").addClass("mce-active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(4)").attr("aria-pressed","true");
        }
        if($(".mce-container.mce-btn-group .mce-btn:nth-child(5)").hasClass("mce-active") && (e.keyCode == 13)){
            console.log("active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(5)").addClass("mce-active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(5)").attr("aria-pressed","true");
        }
    });

}][0]
JS;
    return $initArray;
}

Need a proper solution.

0
, Shweta Danej 3 years 2020-04-07T12:51:53-05:00 0 Answers 74 views 0

Leave an answer

Browse
Browse