Figured this out... The script that handles in the inline editing of rich text fields in Page Editor is \sitecore\shell\Applications\Page Modes\InlineEditingUtil.js. The code that was causing the specific behavior of inserting a <br>
when in the middle of a paragraph is here:
if (e.keyCode === 13) {
var lineBreakTag = Sitecore.WebEditSettings.newLineBreak;
if (lineBreakTag != "p" && lineBreakTag != "div" && lineBreakTag != "br") {
return;
}
e.preventDefault();
var selection = document.getSelection();
var range = selection.getRangeAt(0);
if (lineBreakTag == "br") {
Sitecore.PageModes.InlineEditingUtil.insertBrLineBreak(selection, range);
selection.removeAllRanges();
selection.addRange(range);
return;
}
var focusNode = selection.focusNode.parentNode;
var contentEditable = focusNode.getAttribute("contenteditable");
if (contentEditable) {
focusNode = selection.focusNode;
}
var length = selection.focusNode.length;
var startOrMiddlePosition = selection.focusOffset < length;
var isParagraph = Sitecore.PageModes.InlineEditingUtil.isParagraph(focusNode);
if (startOrMiddlePosition || !isParagraph) {
Sitecore.PageModes.InlineEditingUtil.insertBrLineBreak(selection, range);
selection.removeAllRanges();
selection.addRange(range);
return;
}
......
Specifically this part:
if (startOrMiddlePosition || !isParagraph) {
Sitecore.PageModes.InlineEditingUtil.insertBrLineBreak(selection, range);
which does this:
this.insertBrLineBreak = function (selection, range) {
var brNode = document.createElement("br");
range.insertNode(brNode);
range.setStartAfter(brNode);
range.collapse(true);
};
So I customized the file like so:
if (!isParagraph) {
Sitecore.PageModes.InlineEditingUtil.insertBrLineBreak(selection, range);
selection.removeAllRanges();
selection.addRange(range);
return;
}
else if (startOrMiddlePosition){
Sitecore.PageModes.InlineEditingUtil.insertParagraph(selection, range);
selection.removeAllRanges();
selection.addRange(range);
return;
}
this.insertParagraph = function (selection, range) {
var text1 = range.startContainer.textContent.substring(0, range.startOffset).trim();
var text2 = range.startContainer.textContent.substring(range.startOffset).trim();
var p1 = document.createElement("p");
$(p1).html(text1);
var p2 = document.createElement("p");
$(p2).html(text2);
range.startContainer.remove()
range.insertNode(p2);
range.insertNode(p1);
range.setStart(p2, 0);
range.collapse(true);
};
Now instead of inserting a line break when in the middle of a paragraph, it will split the paragraph into two paragraph nodes.