From d0bb595a1814d367718d1a920ec40372267f2018 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 13 Oct 2023 10:53:12 +0200 Subject: [PATCH] [FIX] web_editor: return all inserted nodes on insert The `insert` command was not returning all inserted nodes. Part-of: odoo/odoo#137064 --- .../static/src/js/editor/odoo-editor/src/commands/commands.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 0d25e024013..7d3dbf33251 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 @@ -233,12 +233,14 @@ export const editorCommands = { reference = child; } } + const lastInsertedNodes = [...containerLastChild.childNodes]; if (containerLastChild.hasChildNodes()) { const toInsert = [...containerLastChild.childNodes]; // Prevent mutation _insertAt(currentNode, [...toInsert], insertBefore); currentNode = insertBefore ? toInsert[0] : currentNode; lastChildNode = toInsert[toInsert.length - 1]; } + const firstInsertedNodes = [...containerFirstChild.childNodes]; if (containerFirstChild.hasChildNodes()) { const toInsert = [...containerFirstChild.childNodes]; // Prevent mutation _insertAt(currentNode, [...toInsert], insertBefore); @@ -310,7 +312,7 @@ export const editorCommands = { newRange.setStart(lastPosition[0], lastPosition[1]); newRange.setEnd(lastPosition[0], lastPosition[1]); selection.addRange(newRange); - return insertedNodes; + return [...firstInsertedNodes, ...insertedNodes, ...lastInsertedNodes]; }, insertFontAwesome: (editor, faClass = 'fa fa-star') => { const insertedNode = editorCommands.insert(editor, document.createElement('i'))[0];