[FIX] web_editor: remove non-connected nodes in applyColor command

Before this commit, the `applyColor` command returned non-connected nodes
(nodes with no parent) in some not well-defined situations, leading to a Warning
when `selection.addRange()` was called by `_processAndApplyColor` with
such non-connected node as argument.

This commit properly removes such non-connected nodes from the array returned
by `applyColor`.

closes odoo/odoo#117166

Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
Rodolpho Lima
2023-04-13 16:40:08 +02:00
parent cdc16116dc
commit 4153c33fc9
@@ -588,13 +588,15 @@ export const editorCommands = {
return font;
});
// Color the selected <font>s and remove uncolored fonts.
for (const font of new Set(fonts)) {
const fontsSet = new Set(fonts);
for (const font of fontsSet) {
colorElement(font, color, mode);
if (!hasColor(font, mode) && !font.hasAttribute('style')) {
for (const child of [...font.childNodes]) {
font.parentNode.insertBefore(child, font);
}
font.parentNode.removeChild(font);
fontsSet.delete(font);
}
}
restoreCursor();
@@ -606,7 +608,7 @@ export const editorCommands = {
newSelection.removeAllRanges();
newSelection.addRange(range);
}
return [...fonts, ...coloredTds];
return [...fontsSet, ...coloredTds];
},
// Table
insertTable: (editor, { rowNumber = 2, colNumber = 2 } = {}) => {