From 1baeea454f86c56047f687126397697c2fdf639b Mon Sep 17 00:00:00 2001 From: abd-msyukyu-odoo Date: Wed, 26 Apr 2023 09:01:41 +0000 Subject: [PATCH] [FIX] web_editor: fontawesome subnodes should make a node non-empty For each node that the `insert` command inserts, the previous node is evaluated and tested to be a `shrunk` block. If it is, it is considered "invisible" and removed. Prior to this commit, an element containing sub-elements with a fontawesome icon was considered to be `isEmptyBlock==='true'` even though it is supposedly visible as it contains that icon. Therefore in cases where multiple nodes are inserted at once, if one of them has only fa-icon nodes as children, that node would not have been inserted. Task-3284580 closes odoo/odoo#119931 X-original-commit: 373c3da609582bd170e1c5924a5c2351eb4706ca Signed-off-by: Thibault Delavallee (tde) --- .../static/src/js/editor/odoo-editor/src/utils/utils.js | 2 +- .../src/js/editor/odoo-editor/test/spec/insert.test.js | 9 +++++++++ 2 files changed, 10 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 612b249f67c..2a8402284d9 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 @@ -1713,7 +1713,7 @@ export function isEmptyBlock(blockEl) { for (const node of nodes) { // There is no text and no double BR, the only thing that could make // this visible is a "visible empty" node like an image. - if (node.nodeName != 'BR' && isSelfClosingElement(node)) { + if (node.nodeName != 'BR' && (isSelfClosingElement(node) || isFontAwesome(node))) { return false; } } diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/insert.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/insert.test.js index e6438d5ac1a..97d134b90ad 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/insert.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/insert.test.js @@ -92,6 +92,15 @@ describe('insert HTML', () => { contentAfter: '
abcdef[]
ghi
', }); }); + it('should keep an "empty" block which contains fontawesome nodes when inserting multiple nodes', async () => { + await testEditor(BasicEditor, { + contentBefore: '

content[]

', + stepFunction: async editor => { + await editor.execCommand('insert', parseHTML('

unwrapped

culprit

after

')); + }, + contentAfter: '

contentunwrapped

culprit

after[]

', + }); + }); it('should not unwrap single node if the selection anchorNode is the editable', async () => { await testEditor(BasicEditor, { contentBefore: '

content

[]',