[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
This commit is contained in:
Nicolas Bayet
2022-09-14 16:17:53 +02:00
parent 73a57231e5
commit 8282a3f7d2
@@ -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';
}