From 4153c33fc9963037467c486364f140f80bee0868 Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Fri, 17 Mar 2023 17:31:37 +0000 Subject: [PATCH] [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) --- .../src/js/editor/odoo-editor/src/commands/commands.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js index 836212b85b4..ef0957787c8 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js @@ -588,13 +588,15 @@ export const editorCommands = { return font; }); // Color the selected 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 } = {}) => {