From 8282a3f7d2baab8dbcdf02431c3a8cff30c52f33 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Tue, 13 Sep 2022 15:18:26 +0000 Subject: [PATCH] [FIX] web_editor: prevent pause step without mouseup Before this commit The call to `historyunPauseSteps('handleSelectionInTable')` is not called without a mouseup. If called from `historySetSelection` in an undo and multiples commands were to be called before a mouse up, no step would be created. Also, `observerUnactive` and `observerActive` should be used rather than `historyPauseStep` and `historyUnpauseStep` for mutations that are visual and local to the user. task-2982429 Part-of: odoo/odoo#100091 --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 13a8c7def77..5e0a0378e63 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 @@ -1683,6 +1683,7 @@ export class OdooEditor extends EventTarget { * @returns {boolean} true if a table was deselected */ deselectTable() { + this.observerUnactive('deselectTable'); let didDeselectTable = false; for (const td of this.editable.querySelectorAll('.o_selected_table, .o_selected_td')) { td.classList.remove('o_selected_td', 'o_selected_table'); @@ -1691,6 +1692,7 @@ export class OdooEditor extends EventTarget { } didDeselectTable = true; } + this.observerActive('deselectTable'); return didDeselectTable; } @@ -2085,7 +2087,7 @@ export class OdooEditor extends EventTarget { } else if (!traversedNodes.every(node => !!closestElement(node, 'td'))) { // The selection goes through a table but also outside of it -> // select the whole table. - this.historyPauseSteps('handleSelectionInTable'); + this.observerUnactive('handleSelectionInTable'); for (const table of new Set(traversedNodes.map(node => closestElement(node, 'table')))) { if (table) { table.classList.toggle('o_selected_table', true); @@ -2095,6 +2097,7 @@ export class OdooEditor extends EventTarget { appliedCustomSelection = true; } } + this.observerActive('handleSelectionInTable'); } else if (ev) { // We're redirected from a mousemove event. const selectedNodes = getSelectedNodes(this.editable); @@ -2129,7 +2132,7 @@ export class OdooEditor extends EventTarget { * @param {Range} range */ _selectTableCells(range) { - this.historyPauseSteps('handleSelectionInTable'); + this.observerUnactive('_selectTableCells'); const table = closestElement(range.startContainer, 'table'); const alreadyHadSelection = table.classList.contains('o_selected_table'); this.deselectTable(); // Undo previous selection. @@ -2152,6 +2155,7 @@ export class OdooEditor extends EventTarget { if (!alreadyHadSelection) { this.toolbarShow(); } + this.observerActive('_selectTableCells'); } /** * If the mouse is hovering over one of the borders of a table cell element, @@ -3593,7 +3597,6 @@ export class OdooEditor extends EventTarget { this._fixSelectionOnContenteditableFalse(); - this.historyUnpauseSteps('handleSelectionInTable'); if (this.toolbar) { this.toolbar.style.pointerEvents = 'auto'; }