From 9e5be974e0b843f484803ec2e8d0a061e2fea734 Mon Sep 17 00:00:00 2001 From: aath-odoo Date: Thu, 6 Oct 2022 06:57:19 +0000 Subject: [PATCH] [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

which results in extra spacing to next list item. After this commit: Now the content is not wrapped in a

which removes the extra spacing as well. Task-2990517 closes odoo/odoo#108434 X-original-commit: b4cf3bcc893e345c25d863c0afaab71bbbfb404c Signed-off-by: David Monjoie (dmo) --- .../src/js/editor/odoo-editor/src/utils/utils.js | 5 ++++- .../js/editor/odoo-editor/test/spec/format.test.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 () => {