[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) <dmo@odoo.com>
This commit is contained in:
Deependra Solanki
2023-04-13 15:26:57 +02:00
parent 8835b3fe7a
commit fceffd238b
2 changed files with 14 additions and 3 deletions
@@ -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);
@@ -4110,6 +4110,15 @@ describe('List', () => {
'<p>abc</p><ul class="o_checklist"><li class="o_checked">[]def</li></ul>',
});
});
it('should outdent the list item without removing the header tag', async () => {
await testEditor(BasicEditor, {
contentBefore:
'<ul><li>abc</li><li class="oe-nested"><ul><li><h1>[]def</h1></li></ul></li></ul>',
stepFunction: deleteBackward,
contentAfter:
'<ul><li>abc</li><li><h1>[]def</h1></li></ul>',
});
});
it.skip('should outdent while nested within a list item', async () => {
await testEditor(BasicEditor, {
removeCheckIds: true,