From 6f972d9f9ca8af721bada0c4e64c5c5750d88d71 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Wed, 10 Nov 2021 13:19:58 +0000 Subject: [PATCH] [FIX] web_editor: undo after dropping a snippet The commit 1b80fe9b56acea09a6784691561df65fe6349f50 made impossible to undo after dropping a snippet. Task-2688104 closes odoo/odoo#79649 X-original-commit: 92b1f78e8de6c343a9d1ef19459522b868cf108f Signed-off-by: David Monjoie (dmo) Signed-off-by: Antoine Guenet --- .../static/src/js/editor/snippets.editor.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 93e2c2c0480..e8d0da844c3 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -2435,22 +2435,27 @@ var SnippetsMenu = Widget.extend({ } self.getEditableArea().find('.oe_drop_zone').droppable('destroy').remove(); + + let $toInsertParent; + let prev; + let next; + if (dropped) { + prev = $toInsert.first()[0].previousSibling; + next = $toInsert.last()[0].nextSibling; + + $toInsertParent = $toInsert.parent(); + $toInsert.detach(); + } + self.options.wysiwyg.odooEditor.observerActive('dragAndDropCreateSnippet'); if (dropped) { - var prev = $toInsert.first()[0].previousSibling; - var next = $toInsert.last()[0].nextSibling; - if (prev) { - $toInsert.detach(); $toInsert.insertAfter(prev); } else if (next) { - $toInsert.detach(); $toInsert.insertBefore(next); } else { - var $parent = $toInsert.parent(); - $toInsert.detach(); - $parent.prepend($toInsert); + $toInsertParent.prepend($toInsert); } var $target = $toInsert;