From 2830b93a3a7ca575bd6a29c34c50c902bb5c8913 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 17 Apr 2019 12:38:40 +0000 Subject: [PATCH] [FIX] web_editor: insert br within a p Have a fieldHTML as: ```

Some text

More text

``` 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 `
` were deleted This was because the code: - split the original `

` into two ( i.e. it became ```

Some text

More text

``` ) - took the last child of the first p, which is a text then fell back to the first p - replaced the whole p with
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) --- addons/web_editor/static/src/js/editor/summernote.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/summernote.js b/addons/web_editor/static/src/js/editor/summernote.js index 36f5becce06..71130f54afb 100644 --- a/addons/web_editor/static/src/js/editor/summernote.js +++ b/addons/web_editor/static/src/js/editor/summernote.js @@ -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
+ $(cur).html(cur.innerHTML + br.outerHTML); } } if (!dom.isVisibleText(node)) {