From 7dfd2e071e94fe8ea03dc4a06a99ac83222d9b27 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Thu, 28 Apr 2022 15:49:38 +0000 Subject: [PATCH] [FIX] web_editor: prevent class to create history steps There is some classes that are technical and should not create steps. Otherwise it compromise the ability to undo/redo or compromise the ability to detect the dirty elements properly. This commit prevent thoses classes additions and removals to create history steps. task-2836351 closes odoo/odoo#91074 Forward-port-of: #90064 X-original-commit: 41d8a0f246a134e2b5292da4db11e67aa9cfb4ed Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/snippets.options.js | 2 ++ .../js/wysiwyg/widgets/link_popover_widget.js | 16 +++++++++++++++- addons/website/static/tests/tours/link_tools.js | 12 ++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index b36ffb1f336..f74bfe1da65 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -6892,7 +6892,9 @@ registry.ColoredLevelBackground = registry.BackgroundToggler.extend({ * @private */ _markColorLevel: function () { + this.options.wysiwyg.odooEditor.observerUnactive('_markColorLevel'); this.$target.addClass('o_colored_level'); + this.options.wysiwyg.odooEditor.observerActive('_markColorLevel'); }, }); diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js index 40cec2acecd..5311833e268 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js @@ -76,13 +76,19 @@ const LinkPopoverWidget = Widget.extend({ container: this.options.wysiwyg.odooEditor.document.body, }) .on('show.bs.popover.link_popover', () => { + this.options.wysiwyg.odooEditor.observerUnactive('show.bs.popover'); this._loadAsyncLinkPreview(); popoverShown = true; }) + .on('inserted.bs.popover', () => { + this.options.wysiwyg.odooEditor.observerActive('show.bs.popover'); + }) .on('hide.bs.popover.link_popover', () => { + this.options.wysiwyg.odooEditor.observerUnactive('hide.bs.popover'); popoverShown = false; }) .on('hidden.bs.popover.link_popover', () => { + this.options.wysiwyg.odooEditor.observerActive('hide.bs.popover'); for (const tooltip of tooltips) { tooltip.hide(); } @@ -261,7 +267,15 @@ LinkPopoverWidget.createFor = async function (parent, targetEl, options) { return null; } const popoverWidget = new this(parent, targetEl, options); - return popoverWidget.appendTo(targetEl).then(() => popoverWidget); + const wysiwyg = $('#wrapwrap').data('wysiwyg'); + if (wysiwyg) { + wysiwyg.odooEditor.observerUnactive('LinkPopoverWidget'); + } + await popoverWidget.appendTo(targetEl) + if (wysiwyg) { + wysiwyg.odooEditor.observerActive('LinkPopoverWidget'); + } + return popoverWidget; }; export default LinkPopoverWidget; diff --git a/addons/website/static/tests/tours/link_tools.js b/addons/website/static/tests/tours/link_tools.js index 69ef7599b04..9102967abab 100644 --- a/addons/website/static/tests/tours/link_tools.js +++ b/addons/website/static/tests/tours/link_tools.js @@ -56,6 +56,18 @@ tour.register('link_tools', { content: "The new link content should be odoo website and url odoo.be", trigger: '#toolbar button[data-original-title="Link Style"]', }, + { + trigger: 'body', + run: () => { + // When doing automated testing, the link popover takes time to + // hide. While hidding, the editor observer is unactive in order to + // prevent the popover mutation to be recorded. In a manual + // scenario, the popover has plenty of time to be hidden and the + // obsever would be re-activated in time. As this problem arise only + // in test, we activate the observer here for the popover. + $('#wrapwrap').data('wysiwyg').odooEditor.observerActive('hide.bs.popover'); + }, + }, { content: "Click on the secondary style button.", trigger: '#toolbar we-button[data-value="secondary"]',