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 6c3a8cb04ca..a5393a81e44 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 @@ -265,12 +265,14 @@ export function applyInlineStyle(editor, applyStyle) { } applyStyle(textNode.parentElement); } - const firstNode = selectedTextNodes[0]; - const lastNode = selectedTextNodes[selectedTextNodes.length - 1]; - if (direction === DIRECTIONS.RIGHT) { - setSelection(firstNode, 0, lastNode, lastNode.length); - } else { - setSelection(lastNode, lastNode.length, firstNode, 0); + if (selectedTextNodes.length) { + const firstNode = selectedTextNodes[0]; + const lastNode = selectedTextNodes[selectedTextNodes.length - 1]; + if (direction === DIRECTIONS.RIGHT) { + setSelection(firstNode, 0, lastNode, lastNode.length); + } else { + setSelection(lastNode, lastNode.length, firstNode, 0); + } } } function addColumn(editor, beforeOrAfter) {