diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index 0a60eb83e85..0e13cc2f926 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -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); } diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js index 40b12e16979..4aeae1f0d4f 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js @@ -775,6 +775,20 @@ describe('setTagName', () => { contentAfter: '

[ab]

', }); }); + it('should not add paragraph tag when selection is changed to normal in list', async () => { + await testEditor(BasicEditor, { + contentBefore: '', + stepFunction: editor => editor.execCommand('setTag', "p"), + contentAfter: `` + }); + }); + it('should not add paragraph tag to normal text in list', async () => { + await testEditor(BasicEditor, { + contentBefore: '', + stepFunction: editor => editor.execCommand('setTag', "p"), + contentAfter: `` + }); + }); }); describe('to heading 1', () => { it('should turn a paragraph into a heading 1', async () => {