Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/wysihtml5.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import "wysihtml5/keyboard/break_list";
import "wysihtml5/keyboard/shortcuts";
import "wysihtml5/keyboard/delete_images";
import "wysihtml5/keyboard/delete_block_elements";
import "wysihtml5/keyboard/line_break";

// Text Substitutions
import "wysihtml5/text_substitutions/auto_link";
Expand Down
31 changes: 31 additions & 0 deletions src/wysihtml5/keyboard/line_break.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Constants } from "../constants";
import { Composer } from "../views/composer";
import dom from "../dom";

/**
* Emulate native browser behaviour of Shift-Enter inserting a <br> instead
* of a new paragraph.
**/
Composer.RegisterKeyboardHandler(function(e) {
return (
e.type === "keydown" &&
e.keyCode == Constants.ENTER_KEY &&
e.shiftKey
);
}, function(editor, composer, e) {
var breakElement = document.createElement("br"),
selectedNode = composer.selection.getSelectedNode();
e.preventDefault();

if (selectedNode.nodeName === "P") {
selectedNode.appendChild(breakElement);
} else if (selectedNode.nodeName === "BR") {
dom.insert(breakElement).after(selectedNode);
} else {
var initialBreakElement = document.createElement("br");
dom.insert(initialBreakElement).after(selectedNode);
dom.insert(breakElement).after(initialBreakElement);
}

composer.selection.setAfter(breakElement);
});