'How to configure TinyMCE 6 to insert a <br> by pressing only Enter (rather than Shift+Enter)?
How can I configure TinyMCE 6 to insert a <br> by pressing only Enter (rather than Shift+Enter)?
For example, when I run the following, I cannot create a new line simply by clicking [Enter]. Pressing [Enter] does nothing. Is there a setting that allows me to click [Enter] rather than having to know about [Shift+Enter]?
<p contenteditable="true" id="myeditor">
Line1
<br>
Line2
</p>
<script type="text/javascript">
tinymce.init({
selector: "#myeditor",
inline: true,
menubar: false,
statusbar: false,
toolbar: "undo redo | bold italic underline strikethrough"
});
</script>
Live example: https://fiddle.tiny.cloud/zciaab/2
Solution 1:[1]
One method to fix this implementation could be to configure the editor.addShortcut API to add a <br>
element whenever the enter keydown event happens.
I believe the syntax is to use (mceSetAttribute, true, '<br>')
method (docs are here) with the addShortcut method.
I've updated the fiddle to show how it could work:https://fiddle.tiny.cloud/Kciaab/4
EDIT: it is the execCommand('InsertLineBreak')
core command method not setAttribute
. Docs Link for core commands.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |