From 992acd25e2e52c80b5f7fda72d5aefcaba37f917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Fri, 9 Sep 2022 12:03:39 +0000 Subject: [PATCH] [FIX] web_editor,website: top menu edition Ensure all the `#top_menu` links are unremovable. This prevent the editor to merge two `` elements together during delete commands. task-2967314 closes odoo/odoo#99966 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 4 ++++ addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 1 + .../static/src/components/wysiwyg_adapter/wysiwyg_adapter.js | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 95bf0ef2911..751f9605fde 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -220,6 +220,7 @@ export class OdooEditor extends EventTarget { showEmptyElementHint: true, defaultLinkAttributes: {}, plugins: [], + getUnremovableElements: () => [], getReadOnlyAreas: () => [], getContentEditableAreas: () => [], getPowerboxElement: () => { @@ -1947,6 +1948,9 @@ export class OdooEditor extends EventTarget { for (const node of this.options.getReadOnlyAreas()) { node.setAttribute('contenteditable', false); } + for (const element of this.options.getUnremovableElements()) { + element.classList.add("oe_unremovable"); + } this.observerActive('_activateContenteditable'); } _stopContenteditable() { diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 00484d49f3a..ce0e6074c0c 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -169,6 +169,7 @@ const Wysiwyg = Widget.extend({ controlHistoryFromDocument: this.options.controlHistoryFromDocument, getContentEditableAreas: this.options.getContentEditableAreas, getReadOnlyAreas: this.options.getReadOnlyAreas, + getUnremovableElements: this.options.getUnremovableElements, defaultLinkAttributes: this.options.userGeneratedContent ? {rel: 'ugc' } : {}, allowCommandVideo: this.options.allowCommandVideo, getYoutubeVideoElement: getYoutubeVideoElement, diff --git a/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js b/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js index 08d4709c41d..c9714bb94d3 100644 --- a/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js +++ b/addons/website/static/src/components/wysiwyg_adapter/wysiwyg_adapter.js @@ -278,6 +278,7 @@ export class WysiwygAdapterComponent extends ComponentAdapter { bindLinkTool: true, showEmptyElementHint: false, getReadOnlyAreas: this._getReadOnlyAreas.bind(this), + getUnremovableElements: this._getUnremovableElements.bind(this), ...this.props.wysiwygOptions, }; } @@ -358,6 +359,9 @@ export class WysiwygAdapterComponent extends ComponentAdapter { _getReadOnlyAreas() { return []; } + _getUnremovableElements () { + return this.$editable[0].querySelectorAll("#top_menu a:not(.oe_unremovable)"); + } /** * This method provides support for the legacy event system. * The supported events are defined in the prototype.