[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) <tde@openerp.com>
This commit is contained in:
abd-msyukyu-odoo
2023-04-27 18:25:15 +02:00
parent 19abfc1f66
commit 1baeea454f
2 changed files with 10 additions and 1 deletions
@@ -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;
}
}
@@ -92,6 +92,15 @@ describe('insert HTML', () => {
contentAfter: '<pre>abcdef[]<br>ghi</pre>',
});
});
it('should keep an "empty" block which contains fontawesome nodes when inserting multiple nodes', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>content[]</p>',
stepFunction: async editor => {
await editor.execCommand('insert', parseHTML('<p>unwrapped</p><div><i class="fa fa-circle-o-notch"></i></div><p>culprit</p><p>after</p>'));
},
contentAfter: '<p>contentunwrapped</p><div><i class="fa fa-circle-o-notch"></i></div><p>culprit</p><p>after[]</p>',
});
});
it('should not unwrap single node if the selection anchorNode is the editable', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>content</p>[]',