diff --git a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js
index d87a332ba4f..5134073f4d5 100644
--- a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js
+++ b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js
@@ -1312,7 +1312,9 @@ export class OdooEditor extends EventTarget {
let start = range.startContainer;
let end = range.endContainer;
// Let the DOM split and delete the range.
- const doJoin = closestBlock(start) !== closestBlock(range.commonAncestorContainer);
+ const doJoin =
+ closestBlock(start) !== closestBlock(range.commonAncestorContainer) ||
+ closestBlock(end) !== closestBlock(range.commonAncestorContainer) ;
let next = nextLeaf(end, this.editable);
const splitEndTd = closestElement(end, 'td') && end.nextSibling;
const contents = range.extractContents();
diff --git a/addons/web_editor/static/lib/odoo-editor/src/commands/deleteBackward.js b/addons/web_editor/static/lib/odoo-editor/src/commands/deleteBackward.js
index b034de53c8b..0b8a01e2185 100644
--- a/addons/web_editor/static/lib/odoo-editor/src/commands/deleteBackward.js
+++ b/addons/web_editor/static/lib/odoo-editor/src/commands/deleteBackward.js
@@ -163,6 +163,7 @@ HTMLElement.prototype.oDeleteBackward = function (offset, alreadyMoved = false,
}
let node = this.childNodes[offset];
+ const nextSibling = this.nextSibling;
let currentNodeIndex = offset;
// `offsetLimit` will ensure we never move nodes that were not initialy in the element
@@ -194,6 +195,20 @@ HTMLElement.prototype.oDeleteBackward = function (offset, alreadyMoved = false,
const { cType } = getState(cursorNode, cursorOffset, DIRECTIONS.LEFT);
if (cType & CTGROUPS.BLOCK && (!alreadyMoved || cType === CTYPES.BLOCK_OUTSIDE)) {
cursorNode.oDeleteBackward(cursorOffset, alreadyMoved, cursorOffset + currentNodeIndex - offset);
+ } else if (!alreadyMoved) {
+ // When removing a block node adjacent to a inline node,
+ // we need to ensure the block node induced line break are kept with a
.
+ // ex :
[]c
dcontent into the div parent + // or we would loose the line break located after the
. + const cursorNodeNode = cursorNode.childNodes[cursorOffset]; + const cursorNodeRightNode = cursorNodeNode ? cursorNodeNode.nextSibling : undefined; + if (cursorNodeRightNode && + cursorNodeRightNode.nodeType === Node.TEXT_NODE && + nextSibling === cursorNodeRightNode) { + moveDest[0].insertBefore(document.createElement('br'), cursorNodeRightNode); + } } } };