[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 <Zinston@users.noreply.github.com>
This commit is contained in:
Sébastien Geelen (sge)
2021-07-16 10:59:42 +00:00
parent 6cf1d464e2
commit fbca03ead5
@@ -465,10 +465,12 @@ export const editorCommands = {
if (font && font.nodeName === 'FONT') {
// Partially selected <font>: 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 <font>.
const previous = node.previousSibling;