Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button to add single line break in CKEditor

I am developing a plugin to show a "Next Line" button on the CKEditor toolbar. But when I start typing and press the next line button its not working on a single click ie I has to click twice to go to the next line.

I am using CKEditor 4.

What should I do extra to go to the next line on a single click. Can any one help me out of this?

This is my plugin.js code

 CKEDITOR.plugins.add('newline',
{
    init: function (editor) {

        var pluginName = 'newline';

        editor.ui.addButton('newline',

            {
                label: 'New Line',
                command: 'NewLine',
                icon: CKEDITOR.plugins.getPath('newline') + 'images/new_line.png'
            });

       var cmd = editor.addCommand('NewLine', { exec: showNewLine });

    }

});

function showNewLine(e) {

   e.insertHtml('<br />');

   // Here if I replace the above line with  e.insertHtml('<br />&nbsp;'); it will work fine but is adding an extra space at the beggining of each line.

}

All I need is a button(when clicked) that works exactly like Shift+Enter in the ckeditor.

like image 604
user2742122 Avatar asked Nov 30 '25 03:11

user2742122


1 Answers

Your button should execute shiftEnter command. It's much more complicated than just inserting <br />.

editor.execCommand( 'shiftEnter' );
like image 51
Reinmar Avatar answered Dec 02 '25 18:12

Reinmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!