From 4f5ca706ca132996302cd373dcabf4a2bb55f008 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Mon, 10 Jul 2023 06:25:58 +0000 Subject: [PATCH] [FIX] web_editor: prevent removal of heading element On a products category page, there is an element ready to host a heading but it's not explicitly marked as unremovable so when the user tries to remove any snippet inside it, the heading host is removed as well. This fixes it by using the `isUnremovable` utility function instead of simply checking for the `oe_unremovable` class. Steps to reproduce the issue this commit fixes: 1. Go into the website module 2. Click "Shop" 3. Click "Furnitures" 4. Click "Edit" 5. Drop a title block in "Drag building blocks here to customize the header for "Furnitures" category." 6. Click the trash bin on your snippet to remove it. It doesn't get removed. Well now it does. task-3383348 closes odoo/odoo#128744 X-original-commit: d1836d2830d098e2c29cca2643b0b354859daeca Signed-off-by: Antoine Guenet (age) Signed-off-by: David Monjoie (dmo) --- .../web_editor/static/src/js/editor/snippets.editor.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 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 57cf4593584..9f093ae8751 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -13,7 +13,7 @@ import {getCSSVariableValue} from "web_editor.utils"; import * as gridUtils from "@web_editor/js/common/grid_layout_utils"; import { sprintf, escape } from "@web/core/utils/strings"; const QWeb = core.qweb; -import {closestElement} from "@web_editor/js/editor/odoo-editor/src/utils/utils"; +import { closestElement, isUnremovable } from "@web_editor/js/editor/odoo-editor/src/utils/utils"; import { debounce, throttleForAnimation } from "@web/core/utils/timing"; import { uniqueId } from "@web/core/utils/functions"; import { sortBy, unique } from "@web/core/utils/arrays"; @@ -201,7 +201,7 @@ var SnippetEditor = Widget.extend({ this.isTargetParentEditable = this.$target.parent().is(':o_editable'); this.isTargetMovable = this.isTargetParentEditable && this.isTargetMovable && !this.$target.hasClass('oe_unmovable'); - this.isTargetRemovable = this.isTargetParentEditable && !this.$target.parent().is('[data-oe-type="image"]') && !this.$target.hasClass('oe_unremovable'); + this.isTargetRemovable = this.isTargetParentEditable && !this.$target.parent().is('[data-oe-type="image"]') && !isUnremovable(this.$target[0]); this.displayOverlayOptions = this.displayOverlayOptions || this.isTargetMovable || !this.isTargetParentEditable; // Initialize move/clone/remove buttons @@ -555,9 +555,10 @@ var SnippetEditor = Widget.extend({ // Consider layout-only elements (like bg-shapes) as empty return el.matches(this.layoutElementsSelector); }); - return isEmpty && !$el.hasClass('oe_structure') && !$el.hasClass('oe_unremovable') + return isEmpty && !$el.hasClass('oe_structure') && !$el.parent().hasClass('carousel-item') - && (!editor || editor.isTargetParentEditable); + && (!editor || editor.isTargetParentEditable) + && !isUnremovable($el[0]); }; var editor = $parent.data('snippet-editor');