From e70a4baf40091fcf328b1864174252af8764bd64 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Mon, 9 Oct 2023 14:09:14 +0200 Subject: [PATCH] [FIX] web_editor: split text node on insert after delete range The `insert` command was splitting the selection's starting text node only if the selection was collapsed. But after deleting the range, the selection is inevitably collapsed and therefore the same should be done. closes odoo/odoo#138549 X-original-commit: 06a375db7e6250b388d410010a3d1c50e8af1326 Signed-off-by: Antoine Guenet (age) Signed-off-by: David Monjoie (dmo) --- .../editor/odoo-editor/src/commands/commands.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js index 397f04f0f10..995ec0f9a86 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js @@ -150,18 +150,17 @@ export const editorCommands = { insert: (editor, content) => { if (!content) return; const selection = editor.document.getSelection(); - const range = selection.getRangeAt(0); let startNode; let insertBefore = false; - if (selection.isCollapsed) { - if (range.startContainer.nodeType === Node.TEXT_NODE) { - insertBefore = !range.startOffset; - splitTextNode(range.startContainer, range.startOffset, DIRECTIONS.LEFT); - startNode = range.startContainer; - } - } else { + if (!selection.isCollapsed) { editor.deleteRange(selection); } + const range = selection.getRangeAt(0); + if (range.startContainer.nodeType === Node.TEXT_NODE) { + insertBefore = !range.startOffset; + splitTextNode(range.startContainer, range.startOffset, DIRECTIONS.LEFT); + startNode = range.startContainer; + } const container = document.createElement('fake-element'); const containerFirstChild = document.createElement('fake-element-fc');