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;