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 d7a0ad0b158..76dc6a61234 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 @@ -1172,6 +1172,26 @@ export class OdooEditor extends EventTarget { historyUnpauseSteps() { this._historyStepsActive = true; } + /** + * Stash the mutations of the current step to re-apply them later. + */ + historyStash() { + if (!this._historyStashedMutations) { + this._historyStashedMutations = []; + } + this._historyStashedMutations.push(...this._currentStep.mutations); + this._currentStep.mutations = []; + } + /** + * Unstash the previously stashed mutations into the current step. + */ + historyUnstash() { + if (!this._currentStep.mutations) { + this._currentStep.mutations = []; + } + this._currentStep.mutations.unshift(...this._historyStashedMutations); + this._historyStashedMutations = []; + } _historyClean() { this._historySteps = []; this._currentStep = { diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 105f4939f38..5c72c19cb78 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1523,6 +1523,10 @@ const Wysiwyg = Widget.extend({ const selection = this.odooEditor.document.getSelection(); const range = selection.rangeCount && selection.getRangeAt(0); const hadNonCollapsedSelection = range && !selection.isCollapsed; + // The color_leave event will revert the mutations with + // `historyRevertCurrentStep`. We must stash the current + // mutations to prevent them from being reverted. + this.odooEditor.historyStash(); colorpicker = new ColorPaletteWidget(this, { excluded: ['transparent_grayscale'], $editable: $(this.odooEditor.editable), // Our parent is the root widget, we can't retrieve the editable section from it... @@ -1535,6 +1539,8 @@ const Wysiwyg = Widget.extend({ if (hadNonCollapsedSelection) { this.odooEditor.historyResetLatestComputedSelection(true); } + // Unstash the mutations now that the color is picked. + this.odooEditor.historyUnstash(); this._processAndApplyColor(eventName, ev.data.color); this._updateEditorUI(); });