Reputation: 623
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 /> '); 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.
Upvotes: 3
Views: 3732
Reputation: 22023
Your button should execute shiftEnter
command. It's much more complicated than just inserting <br />
.
editor.execCommand( 'shiftEnter' );
Upvotes: 2