Reputation: 207
I've been using TinyMCE (v4 at the moment, but this question is valid for v5 as well) as an editor for content that is eventually turned into Word documents.
Pressing shift + enter
on TinyMCE inserts a line break <br />
rather than a return (i.e., creating a new <p>
). Is there any way to make shift + enter
behave just as enter
? In other words, is there any way to disable shift + enter
?
If anyone's interested as to why I'm asking:
To make it as similar to editing text on Word as possible, I made it so that <p>
elements have no margins at all. This way, the document looks the same on the editor and on Word. Line breaks look the same on the editor, but when converted to Word, their behaviour is different when the text orientation is set to justified. Lines ending with a line break get stretched to the full width of the document; lines ending with a return don't get stretched at all. That's the behaviour I'd like to have.
Upvotes: 1
Views: 1329
Reputation: 13744
TinyMCE has APIs you can use to be notified when a key is pressed and you can look at that event to see if Shift + Enter has been pressed. The code to do this can go in your configuration:
setup: function(editor) {
editor.on('keydown', function (event) {
if (event.keyCode == 13 && event.shiftKey) {
console.log(event);
event.preventDefault();
event.stopPropagation();
return false;
}
});
}
Here is a complete TinyMCE Fiddle: http://fiddle.tinymce.com/LQgaab
Upvotes: 3