From ebb4d39571caee70469c9580dcd5946489084a65 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Wed, 13 Oct 2021 13:33:59 +0000 Subject: [PATCH] [FIX] web_editor: activate the redo button when needed Because the `_historyStepsStates` was not fully set at the time of calling `historyStep` in `historyUndo` or `historyRedo`, the listener for the event "historyStep" was triggered to early and `historyCanRedo` at that time could not possibly be accurate. This commit call `historyStep` after setting all ids in `_historyStepsStates`. task-2667885 X-original-commit: 659b530516e13df77eed6254b81e72b8009a71bf Part-of: odoo/odoo#79620 --- .../static/lib/odoo-editor/src/OdooEditor.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js index d9d4edc410c..d3ddd0e239a 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js @@ -637,7 +637,7 @@ export class OdooEditor extends EventTarget { } // One step completed: apply to vDOM, setup next history step - historyStep(skipRollback = false) { + historyStep(skipRollback = false, { stepId } = {}) { if (!this._historyStepsActive) { return; } @@ -654,7 +654,7 @@ export class OdooEditor extends EventTarget { return false; } - currentStep.id = this._generateId(); + currentStep.id = stepId || this._generateId(); const previousStep = peek(this._historySteps); currentStep.clientId = this._collabClientId; currentStep.previousStepId = previousStep.id; @@ -752,10 +752,10 @@ export class OdooEditor extends EventTarget { // Consider the position consumed. this._historyStepsStates.set(this._historySteps[pos].id, 'consumed'); this.historyRevert(this._historySteps[pos]); - this.historyStep(true); // Consider the last position of the history as an undo. - const undoStep = this._historySteps[this._historySteps.length - 1]; - this._historyStepsStates.set(undoStep.id, 'undo'); + const stepId = this._generateId(); + this._historyStepsStates.set(stepId, 'undo'); + this.historyStep(true, { stepId }); this.dispatchEvent(new Event('historyUndo')); } } @@ -770,9 +770,9 @@ export class OdooEditor extends EventTarget { this._historyStepsStates.set(this._historySteps[pos].id, 'consumed'); this.historyRevert(this._historySteps[pos]); this.historySetSelection(this._historySteps[pos]); - this.historyStep(true); - const lastStep = this._historySteps[this._historySteps.length - 1]; - this._historyStepsStates.set(lastStep.id, 'redo'); + const stepId = this._generateId(); + this._historyStepsStates.set(stepId, 'redo'); + this.historyStep(true, { stepId }); this.dispatchEvent(new Event('historyRedo')); } }