[FIX] web_editor: spacing when changing format in checklists

Before this commit:

On changing style of a list item to normal it wrapped the content in a <p> which
results in extra spacing to next list item.

After this commit:

Now the content is not wrapped in a <p> which removes the extra spacing as well.

Task-2990517

closes odoo/odoo#108434

X-original-commit: b4cf3bcc893e345c25d863c0afaab71bbbfb404c
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
aath-odoo
2022-12-21 16:36:54 +01:00
parent 0d0ab5d8db
commit 9e5be974e0
2 changed files with 18 additions and 1 deletions
@@ -1982,8 +1982,11 @@ export function setTagName(el, newTagName) {
while (el.firstChild) {
n.append(el.firstChild);
}
if (el.tagName === 'LI') {
const closestLi = el.closest('li');
if (el.tagName === 'LI' && newTagName !== 'p') {
el.append(n);
} else if (closestLi && newTagName === 'p') {
closestLi.replaceChildren(...n.childNodes);
} else {
el.parentNode.replaceChild(n, el);
}
@@ -775,6 +775,20 @@ describe('setTagName', () => {
contentAfter: '<div><p>[ab]</p></div>',
});
});
it('should not add paragraph tag when selection is changed to normal in list', async () => {
await testEditor(BasicEditor, {
contentBefore: '<ul><li><h1>[abcd]</h1></li></ul>',
stepFunction: editor => editor.execCommand('setTag', "p"),
contentAfter: `<ul><li>[abcd]</li></ul>`
});
});
it('should not add paragraph tag to normal text in list', async () => {
await testEditor(BasicEditor, {
contentBefore: '<ul><li>[abcd]</li></ul>',
stepFunction: editor => editor.execCommand('setTag', "p"),
contentAfter: `<ul><li>[abcd]</li></ul>`
});
});
});
describe('to heading 1', () => {
it('should turn a paragraph into a heading 1', async () => {