From fbca03ead53e3f632523a41acb7846aafcced155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Wed, 14 Jul 2021 08:13:08 +0000 Subject: [PATCH] [FIX] web_editor: fix traceback in applyColor When the selectedChildren array was empty it generated an error and a traceback appeared in Odoo. Task-2580158 closes odoo/odoo#73846 X-original-commit: 65b8ffb56485895cc08be024b18928d1e51949b7 Signed-off-by: Antoine Guenet --- .../static/lib/odoo-editor/src/commands/commands.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/static/lib/odoo-editor/src/commands/commands.js b/addons/web_editor/static/lib/odoo-editor/src/commands/commands.js index 630c20935ca..256fc4ec27e 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/commands/commands.js +++ b/addons/web_editor/static/lib/odoo-editor/src/commands/commands.js @@ -465,10 +465,12 @@ export const editorCommands = { if (font && font.nodeName === 'FONT') { // Partially selected : split it. const selectedChildren = children.filter(child => selectedNodes.includes(child)); - const after = selectedChildren[selectedChildren.length - 1].nextSibling; - font = after ? splitElement(font, childNodeIndex(after))[0] : font; - const before = selectedChildren[0].previousSibling; - font = before ? splitElement(font, childNodeIndex(before) + 1)[1] : font; + if (selectedChildren.length) { + const after = selectedChildren[selectedChildren.length - 1].nextSibling; + font = after ? splitElement(font, childNodeIndex(after))[0] : font; + const before = selectedChildren[0].previousSibling; + font = before ? splitElement(font, childNodeIndex(before) + 1)[1] : font; + } } else if (node.nodeType === Node.TEXT_NODE && isVisibleStr(node)) { // Node is a visible text node: wrap it in a . const previous = node.previousSibling;