[FIX] web_editor: insert br within a p

Have a fieldHTML as:
```
<p>
Some text
<br>
<br>
More text
</p>
```

In the Html field widget, place your cursor before the "M"
press Enter to insert a newline

Before this commit "Some text" and the subsequent `<br>` were deleted
This was because the code:
- split the original `<p>` into two
( i.e. it became
```
<p>
Some text
<br>
<br>
</p>
<p>
More text
</p>
```
)
- took the last child of the first p, which is a text then fell back to the first p
- replaced the whole p with <br>

After this commit, the original p is still split, but we append the br to it instead of replacing it

closes odoo/odoo#32777

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2019-04-17 12:45:52 +00:00
parent c8b91b0a15
commit 2830b93a3a
@@ -1259,9 +1259,11 @@ $.summernote.pluginEvents.enter = function (event, editor, layoutInfo) {
} else {
node = dom.splitTree(last, {'node': r.sc, 'offset': r.so}) || r.sc;
if (!contentBefore) {
// dom.node chooses the parent if node is text
var cur = dom.node(dom.lastChild(node.previousSibling));
if (!dom.isBR(cur)) {
$(cur).html(br);
// We should concat what was before with a <br>
$(cur).html(cur.innerHTML + br.outerHTML);
}
}
if (!dom.isVisibleText(node)) {