diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/deleteBackward.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/deleteBackward.js index 4d984f444e2..f66950b0751 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/deleteBackward.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/deleteBackward.js @@ -25,6 +25,7 @@ import { isSelfClosingElement, isNotEditableNode, createDOMPathGenerator, + closestElement, } from '../utils/utils.js'; Text.prototype.oDeleteBackward = function (offset, alreadyMoved = false) { @@ -91,8 +92,8 @@ HTMLElement.prototype.oDeleteBackward = function (offset, alreadyMoved = false, throw UNBREAKABLE_ROLLBACK_CODE; } const parentEl = this.parentNode; - - if (!isBlock(this) || isSelfClosingElement(this)) { + const closestLi = closestElement(this, 'li'); + if ((closestLi && !closestLi.previousElementSibling) || !isBlock(this) || isSelfClosingElement(this)) { /** * Backspace at the beginning of an inline node, nothing has to be * done: propagate the backspace. If the node was empty, we remove @@ -141,7 +142,8 @@ HTMLElement.prototype.oDeleteBackward = function (offset, alreadyMoved = false, */ if ( !this.previousElementSibling && - ['BLOCKQUOTE', 'H1', 'H2', 'H3', 'PRE'].includes(this.nodeName) + ['BLOCKQUOTE', 'H1', 'H2', 'H3', 'PRE'].includes(this.nodeName) && + !closestLi ) { const p = document.createElement('p'); p.replaceChildren(...this.childNodes); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/list.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/list.test.js index fbd516d9e51..dbb42fba1ab 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/list.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/list.test.js @@ -4110,6 +4110,15 @@ describe('List', () => { '

abc

', }); }); + it('should outdent the list item without removing the header tag', async () => { + await testEditor(BasicEditor, { + contentBefore: + '', + stepFunction: deleteBackward, + contentAfter: + '', + }); + }); it.skip('should outdent while nested within a list item', async () => { await testEditor(BasicEditor, { removeCheckIds: true,