From 105dd6e4ddf8c8bf445bdf71f95b22b1e6ab9425 Mon Sep 17 00:00:00 2001 From: vishal padhiyar Date: Fri, 3 Feb 2023 05:31:48 +0000 Subject: [PATCH] [FIX] web_editor: page crash on colour selection Before this commit: When we select text and take the selection to the hex input box and then try again to add a solid color, it gives us a traceback. After this commit: Now it did not give traceback. Task-2965091 closes odoo/odoo#116539 X-original-commit: 981713bd024a98f5d9099bfec8458224dac32a32 Signed-off-by: David Monjoie (dmo) --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index c8e7310e478..9fda8d74f00 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1767,14 +1767,14 @@ const Wysiwyg = Widget.extend({ } const coloredElements = this.odooEditor.execCommand('applyColor', color, eventName === 'foreColor' ? 'color' : 'backgroundColor', this.lastMediaClicked); - const coloredTds = coloredElements.filter(coloredElement => coloredElement.classList.contains('o_selected_td')); + const coloredTds = coloredElements && coloredElements.length && coloredElements.filter(coloredElement => coloredElement.classList.contains('o_selected_td')); if (coloredTds.length) { const propName = eventName === 'foreColor' ? 'color' : 'background-color'; for (const td of coloredTds) { // Make it important so it has priority over selection color. td.style.setProperty(propName, td.style[propName], previewMode ? 'important' : ''); } - } else if (!this.lastMediaClicked) { + } else if (!this.lastMediaClicked && coloredElements && coloredElements.length) { // Ensure the selection in the fonts tags, otherwise an undetermined // race condition could generate a wrong selection later. const first = coloredElements[0];