From fceffd238b889326f4df48c09c5d19dc26401333 Mon Sep 17 00:00:00 2001 From: Deependra Solanki Date: Thu, 2 Mar 2023 10:38:04 +0000 Subject: [PATCH] [FIX] web_editor: should not remove tag on backspace in nested li Before this commit: When we create a nested list and change a tag of the one of the list item in nested list and press backspace from start it removes the tag. After this commit: Now pressing backspace from the start tag, the tag is not removed. task - 3147461 closes odoo/odoo#118353 X-original-commit: 7504dc1adc50916b9a408c3307832ab45ed5174b Signed-off-by: David Monjoie (dmo) --- .../js/editor/odoo-editor/src/commands/deleteBackward.js | 8 +++++--- .../src/js/editor/odoo-editor/test/spec/list.test.js | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) 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,